
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>GDAL API &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../../../genindex.html" />
    <link rel="search" title="搜索" href="../../../search.html" />
    <link rel="next" title="用 GeoIP2 进行地理定位" href="geoip2.html" />
    <link rel="prev" title="GEOS API" href="geos.html" />



 
<script src="../../../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="geos.html" title="GEOS API">previous</a>
     |
    <a href="../../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="geoip2.html" title="用 GeoIP2 进行地理定位">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-gis-gdal">
            
  <div class="section" id="s-module-django.contrib.gis.gdal">
<span id="s-gdal-api"></span><span id="module-django.contrib.gis.gdal"></span><span id="gdal-api"></span><h1>GDAL API<a class="headerlink" href="#module-django.contrib.gis.gdal" title="永久链接至标题">¶</a></h1>
<p><a class="reference external" href="https://gdal.org/">GDAL</a> stands for <strong>Geospatial Data Abstraction Library</strong>,
and is a veritable &quot;Swiss army knife&quot; of GIS data functionality.  A subset
of GDAL is the <a class="reference external" href="https://gdal.org/user/vector_data_model.html">OGR</a> Simple Features Library, which specializes
in reading and writing vector geographic data in a variety of standard
formats.</p>
<p>GeoDjango provides a high-level Python interface for some of the
capabilities of OGR, including the reading and coordinate transformation
of vector spatial data and minimal support for GDAL's features with respect
to raster (image) data.</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">Although the module is named <code class="docutils literal notranslate"><span class="pre">gdal</span></code>, GeoDjango only supports some of the
capabilities of OGR and GDAL's raster features at this time.</p>
</div>
<div class="section" id="s-overview">
<span id="overview"></span><h2>概况<a class="headerlink" href="#overview" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-sample-data">
<span id="s-gdal-sample-data"></span><span id="sample-data"></span><span id="gdal-sample-data"></span><h3>样本数据<a class="headerlink" href="#sample-data" title="永久链接至标题">¶</a></h3>
<p>The GDAL/OGR tools described here are designed to help you read in
your geospatial data, in order for most of them to be useful you have
to have some data to work with.  If you're starting out and don't yet
have any data of your own to use, GeoDjango tests contain a number of
data sets that you can use for testing. You can download them here:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ wget https://raw.githubusercontent.com/django/django/main/tests/gis_tests/data/cities/cities.{shp,prj,shx,dbf}
$ wget https://raw.githubusercontent.com/django/django/main/tests/gis_tests/data/rasters/raster.tif
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-vector-data-source-objects">
<span id="vector-data-source-objects"></span><h2>矢量数据源对象<a class="headerlink" href="#vector-data-source-objects" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-datasource">
<span id="datasource"></span><h3><code class="docutils literal notranslate"><span class="pre">DataSource</span></code><a class="headerlink" href="#datasource" title="永久链接至标题">¶</a></h3>
<p><a class="reference internal" href="#django.contrib.gis.gdal.DataSource" title="django.contrib.gis.gdal.DataSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">DataSource</span></code></a> is a wrapper for the OGR data source object that
supports reading data from a variety of OGR-supported geospatial file
formats and data sources using a consistent interface.  Each
data source is represented by a <a class="reference internal" href="#django.contrib.gis.gdal.DataSource" title="django.contrib.gis.gdal.DataSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">DataSource</span></code></a> object which contains
one or more layers of data.  Each layer, represented by a <a class="reference internal" href="#django.contrib.gis.gdal.Layer" title="django.contrib.gis.gdal.Layer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Layer</span></code></a>
object, contains some number of geographic features (<a class="reference internal" href="#django.contrib.gis.gdal.Feature" title="django.contrib.gis.gdal.Feature"><code class="xref py py-class docutils literal notranslate"><span class="pre">Feature</span></code></a>),
information about the type of features contained in that layer (e.g.
points, polygons, etc.), as well as the names and types of any
additional fields (<a class="reference internal" href="#django.contrib.gis.gdal.Field" title="django.contrib.gis.gdal.Field"><code class="xref py py-class docutils literal notranslate"><span class="pre">Field</span></code></a>) of data that may be associated with
each feature in that layer.</p>
<dl class="class">
<dt id="django.contrib.gis.gdal.DataSource">
<em class="property">class </em><code class="descname">DataSource</code>(<em>ds_input</em>, <em>encoding='utf-8'</em>)<a class="headerlink" href="#django.contrib.gis.gdal.DataSource" title="永久链接至目标">¶</a></dt>
<dd><p>The constructor for <code class="docutils literal notranslate"><span class="pre">DataSource</span></code> only requires one parameter: the path of
the file you want to read. However, OGR also supports a variety of more
complex data sources, including databases, that may be accessed by passing
a special name string instead of a path. For more information, see the
<a class="reference external" href="https://gdal.org/drivers/vector/">OGR Vector Formats</a> documentation. The <a class="reference internal" href="#django.contrib.gis.gdal.DataSource.name" title="django.contrib.gis.gdal.DataSource.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> property of a
<code class="docutils literal notranslate"><span class="pre">DataSource</span></code> instance gives the OGR name of the underlying data source
that it is using.</p>
<p>The optional <code class="docutils literal notranslate"><span class="pre">encoding</span></code> parameter allows you to specify a non-standard
encoding of the strings in the source. This is typically useful when you
obtain <code class="docutils literal notranslate"><span class="pre">DjangoUnicodeDecodeError</span></code> exceptions while reading field values.</p>
<p>Once you've created your <code class="docutils literal notranslate"><span class="pre">DataSource</span></code>, you can find out how many layers
of data it contains by accessing the <a class="reference internal" href="#django.contrib.gis.gdal.DataSource.layer_count" title="django.contrib.gis.gdal.DataSource.layer_count"><code class="xref py py-attr docutils literal notranslate"><span class="pre">layer_count</span></code></a> property, or
(equivalently) by using the <code class="docutils literal notranslate"><span class="pre">len()</span></code> function. For information on
accessing the layers of data themselves, see the next section:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.contrib.gis.gdal</span> <span class="kn">import</span> <span class="n">DataSource</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ds</span> <span class="o">=</span> <span class="n">DataSource</span><span class="p">(</span><span class="s1">&#39;/path/to/your/cities.shp&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ds</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;/path/to/your/cities.shp&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ds</span><span class="o">.</span><span class="n">layer_count</span>                  <span class="c1"># This file only contains one layer</span>
<span class="go">1</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.DataSource.layer_count">
<code class="descname">layer_count</code><a class="headerlink" href="#django.contrib.gis.gdal.DataSource.layer_count" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the number of layers in the data source.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.DataSource.name">
<code class="descname">name</code><a class="headerlink" href="#django.contrib.gis.gdal.DataSource.name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the name of the data source.</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.2:</span> <p>增加了对 <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.10)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> <code class="docutils literal notranslate"><span class="pre">ds_input</span></code> 的支持。</p>
</div>
</dd></dl>

</div>
<div class="section" id="s-layer">
<span id="layer"></span><h3><code class="docutils literal notranslate"><span class="pre">Layer</span></code><a class="headerlink" href="#layer" title="永久链接至标题">¶</a></h3>
<dl class="class">
<dt id="django.contrib.gis.gdal.Layer">
<em class="property">class </em><code class="descname">Layer</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer" title="永久链接至目标">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">Layer</span></code> is a wrapper for a layer of data in a <code class="docutils literal notranslate"><span class="pre">DataSource</span></code> object. You
never create a <code class="docutils literal notranslate"><span class="pre">Layer</span></code> object directly. Instead, you retrieve them from
a <a class="reference internal" href="#django.contrib.gis.gdal.DataSource" title="django.contrib.gis.gdal.DataSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">DataSource</span></code></a> object, which is essentially a standard Python
container of <code class="docutils literal notranslate"><span class="pre">Layer</span></code> objects. For example, you can access a specific
layer by its index (e.g. <code class="docutils literal notranslate"><span class="pre">ds[0]</span></code> to access the first layer), or you can
iterate over all the layers in the container in a <code class="docutils literal notranslate"><span class="pre">for</span></code> loop. The
<code class="docutils literal notranslate"><span class="pre">Layer</span></code> itself acts as a container for geometric features.</p>
<p>Typically, all the features in a given layer have the same geometry type.
The <a class="reference internal" href="#django.contrib.gis.gdal.Layer.geom_type" title="django.contrib.gis.gdal.Layer.geom_type"><code class="xref py py-attr docutils literal notranslate"><span class="pre">geom_type</span></code></a> property of a layer is an <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeomType" title="django.contrib.gis.gdal.OGRGeomType"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeomType</span></code></a> that
identifies the feature type. We can use it to print out some basic
information about each layer in a <a class="reference internal" href="#django.contrib.gis.gdal.DataSource" title="django.contrib.gis.gdal.DataSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">DataSource</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">layer</span> <span class="ow">in</span> <span class="n">ds</span><span class="p">:</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Layer &quot;</span><span class="si">%s</span><span class="s1">&quot;: </span><span class="si">%i</span><span class="s1"> </span><span class="si">%s</span><span class="s1">s&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">layer</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">layer</span><span class="p">),</span> <span class="n">layer</span><span class="o">.</span><span class="n">geom_type</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
<span class="gp">...</span>
<span class="go">Layer &quot;cities&quot;: 3 Points</span>
</pre></div>
</div>
<p>The example output is from the cities data source, loaded above, which
evidently contains one layer, called <code class="docutils literal notranslate"><span class="pre">&quot;cities&quot;</span></code>, which contains three
point features. For simplicity, the examples below assume that you've
stored that layer in the variable <code class="docutils literal notranslate"><span class="pre">layer</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span> <span class="o">=</span> <span class="n">ds</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Layer.name">
<code class="descname">name</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer.name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the name of this layer in the data source.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;cities&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Layer.num_feat">
<code class="descname">num_feat</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer.num_feat" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the number of features in the layer. Same as <code class="docutils literal notranslate"><span class="pre">len(layer)</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">num_feat</span>
<span class="go">3</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Layer.geom_type">
<code class="descname">geom_type</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer.geom_type" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the geometry type of the layer, as an <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeomType" title="django.contrib.gis.gdal.OGRGeomType"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeomType</span></code></a> object:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">geom_type</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;Point&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Layer.num_fields">
<code class="descname">num_fields</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer.num_fields" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the number of fields in the layer, i.e the number of fields of
data associated with each feature in the layer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">num_fields</span>
<span class="go">4</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Layer.fields">
<code class="descname">fields</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer.fields" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a list of the names of each of the fields in this layer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">fields</span>
<span class="go">[&#39;Name&#39;, &#39;Population&#39;, &#39;Density&#39;, &#39;Created&#39;]</span>
</pre></div>
</div>
<p>Returns a list of the data types of each of the fields in this layer. These
are subclasses of <code class="docutils literal notranslate"><span class="pre">Field</span></code>, discussed below:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">ft</span><span class="o">.</span><span class="vm">__name__</span> <span class="k">for</span> <span class="n">ft</span> <span class="ow">in</span> <span class="n">layer</span><span class="o">.</span><span class="n">field_types</span><span class="p">]</span>
<span class="go">[&#39;OFTString&#39;, &#39;OFTReal&#39;, &#39;OFTReal&#39;, &#39;OFTDate&#39;]</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Layer.field_widths">
<code class="descname">field_widths</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer.field_widths" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a list of the maximum field widths for each of the fields in this
layer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">field_widths</span>
<span class="go">[80, 11, 24, 10]</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Layer.field_precisions">
<code class="descname">field_precisions</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer.field_precisions" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a list of the numeric precisions for each of the fields in this
layer. This is meaningless (and set to zero) for non-numeric fields:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">field_precisions</span>
<span class="go">[0, 0, 15, 0]</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Layer.extent">
<code class="descname">extent</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer.extent" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the spatial extent of this layer, as an <a class="reference internal" href="#django.contrib.gis.gdal.Envelope" title="django.contrib.gis.gdal.Envelope"><code class="xref py py-class docutils literal notranslate"><span class="pre">Envelope</span></code></a> object:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">extent</span><span class="o">.</span><span class="n">tuple</span>
<span class="go">(-104.609252, 29.763374, -95.23506, 38.971823)</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Layer.srs">
<code class="descname">srs</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer.srs" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Property that returns the <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> associated with this
layer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">layer</span><span class="o">.</span><span class="n">srs</span><span class="p">)</span>
<span class="go">GEOGCS[&quot;GCS_WGS_1984&quot;,</span>
<span class="go">    DATUM[&quot;WGS_1984&quot;,</span>
<span class="go">        SPHEROID[&quot;WGS_1984&quot;,6378137,298.257223563]],</span>
<span class="go">    PRIMEM[&quot;Greenwich&quot;,0],</span>
<span class="go">    UNIT[&quot;Degree&quot;,0.017453292519943295]]</span>
</pre></div>
</div>
<p>If the <a class="reference internal" href="#django.contrib.gis.gdal.Layer" title="django.contrib.gis.gdal.Layer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Layer</span></code></a> has no spatial reference information associated
with it, <code class="docutils literal notranslate"><span class="pre">None</span></code> is returned.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Layer.spatial_filter">
<code class="descname">spatial_filter</code><a class="headerlink" href="#django.contrib.gis.gdal.Layer.spatial_filter" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Property that may be used to retrieve or set a spatial filter for this
layer. A spatial filter can only be set with an <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a>
instance, a 4-tuple extent, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. When set with something other than
<code class="docutils literal notranslate"><span class="pre">None</span></code>, only features that intersect the filter will be returned when
iterating over the layer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">layer</span><span class="o">.</span><span class="n">spatial_filter</span><span class="p">)</span>
<span class="go">None</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">layer</span><span class="p">))</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">feat</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Name&#39;</span><span class="p">)</span> <span class="k">for</span> <span class="n">feat</span> <span class="ow">in</span> <span class="n">layer</span><span class="p">]</span>
<span class="go">[&#39;Pueblo&#39;, &#39;Lawrence&#39;, &#39;Houston&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ks_extent</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="mf">102.051</span><span class="p">,</span> <span class="mf">36.99</span><span class="p">,</span> <span class="o">-</span><span class="mf">94.59</span><span class="p">,</span> <span class="mf">40.00</span><span class="p">)</span> <span class="c1"># Extent for state of Kansas</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">spatial_filter</span> <span class="o">=</span> <span class="n">ks_extent</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">layer</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">feat</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Name&#39;</span><span class="p">)</span> <span class="k">for</span> <span class="n">feat</span> <span class="ow">in</span> <span class="n">layer</span><span class="p">]</span>
<span class="go">[&#39;Lawrence&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">spatial_filter</span> <span class="o">=</span> <span class="kc">None</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">layer</span><span class="p">)</span>
<span class="go">3</span>
</pre></div>
</div>
<dl class="method">
<dt id="django.contrib.gis.gdal.Layer.get_fields">
<code class="descname">get_fields</code>()<a class="headerlink" href="#django.contrib.gis.gdal.Layer.get_fields" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>A method that returns a list of the values of a given field for each
feature in the layer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">layer</span><span class="o">.</span><span class="n">get_fields</span><span class="p">(</span><span class="s1">&#39;Name&#39;</span><span class="p">)</span>
<span class="go">[&#39;Pueblo&#39;, &#39;Lawrence&#39;, &#39;Houston&#39;]</span>
</pre></div>
</div>
<dl class="method">
<dt id="django.contrib.gis.gdal.Layer.get_geoms">
<code class="descname">get_geoms</code>(<em>geos=False</em>)<a class="headerlink" href="#django.contrib.gis.gdal.Layer.get_geoms" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>A method that returns a list containing the geometry of each feature in the
layer. If the optional argument <code class="docutils literal notranslate"><span class="pre">geos</span></code> is set to <code class="docutils literal notranslate"><span class="pre">True</span></code> then the
geometries are converted to <a class="reference internal" href="geos.html#django.contrib.gis.geos.GEOSGeometry" title="django.contrib.gis.geos.GEOSGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">GEOSGeometry</span></code></a>
objects. Otherwise, they are returned as <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> objects:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">pt</span><span class="o">.</span><span class="n">tuple</span> <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">layer</span><span class="o">.</span><span class="n">get_geoms</span><span class="p">()]</span>
<span class="go">[(-104.609252, 38.255001), (-95.23506, 38.971823), (-95.363151, 29.763374)]</span>
</pre></div>
</div>
<dl class="method">
<dt id="django.contrib.gis.gdal.Layer.test_capability">
<code class="descname">test_capability</code>(<em>capability</em>)<a class="headerlink" href="#django.contrib.gis.gdal.Layer.test_capability" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a boolean indicating whether this layer supports the given
capability (a string).  Examples of valid capability strings include:
<code class="docutils literal notranslate"><span class="pre">'RandomRead'</span></code>, <code class="docutils literal notranslate"><span class="pre">'SequentialWrite'</span></code>, <code class="docutils literal notranslate"><span class="pre">'RandomWrite'</span></code>,
<code class="docutils literal notranslate"><span class="pre">'FastSpatialFilter'</span></code>, <code class="docutils literal notranslate"><span class="pre">'FastFeatureCount'</span></code>, <code class="docutils literal notranslate"><span class="pre">'FastGetExtent'</span></code>,
<code class="docutils literal notranslate"><span class="pre">'CreateField'</span></code>, <code class="docutils literal notranslate"><span class="pre">'Transactions'</span></code>, <code class="docutils literal notranslate"><span class="pre">'DeleteFeature'</span></code>, and
<code class="docutils literal notranslate"><span class="pre">'FastSetNextByIndex'</span></code>.</p>
</dd></dl>

</div>
<div class="section" id="s-feature">
<span id="feature"></span><h3><code class="docutils literal notranslate"><span class="pre">Feature</span></code><a class="headerlink" href="#feature" title="永久链接至标题">¶</a></h3>
<dl class="class">
<dt id="django.contrib.gis.gdal.Feature">
<em class="property">class </em><code class="descname">Feature</code><a class="headerlink" href="#django.contrib.gis.gdal.Feature" title="永久链接至目标">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">Feature</span></code> wraps an OGR feature. You never create a <code class="docutils literal notranslate"><span class="pre">Feature</span></code> object
directly. Instead, you retrieve them from a <a class="reference internal" href="#django.contrib.gis.gdal.Layer" title="django.contrib.gis.gdal.Layer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Layer</span></code></a> object. Each
feature consists of a geometry and a set of fields containing additional
properties. The geometry of a field is accessible via its <code class="docutils literal notranslate"><span class="pre">geom</span></code> property,
which returns an <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> object. A <code class="docutils literal notranslate"><span class="pre">Feature</span></code> behaves like a
standard Python container for its fields, which it returns as <a class="reference internal" href="#django.contrib.gis.gdal.Field" title="django.contrib.gis.gdal.Field"><code class="xref py py-class docutils literal notranslate"><span class="pre">Field</span></code></a>
objects: you can access a field directly by its index or name, or you can
iterate over a feature's fields, e.g. in a <code class="docutils literal notranslate"><span class="pre">for</span></code> loop.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Feature.geom">
<code class="descname">geom</code><a class="headerlink" href="#django.contrib.gis.gdal.Feature.geom" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the geometry for this feature, as an <code class="docutils literal notranslate"><span class="pre">OGRGeometry</span></code> object:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="o">.</span><span class="n">geom</span><span class="o">.</span><span class="n">tuple</span>
<span class="go">(-104.609252, 38.255001)</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Feature.get">
<code class="descname">get</code><a class="headerlink" href="#django.contrib.gis.gdal.Feature.get" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>A method that returns the value of the given field (specified by name)
for this feature, <strong>not</strong> a <code class="docutils literal notranslate"><span class="pre">Field</span></code> wrapper object:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Population&#39;</span><span class="p">)</span>
<span class="go">102121</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Feature.geom_type">
<code class="descname">geom_type</code><a class="headerlink" href="#django.contrib.gis.gdal.Feature.geom_type" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the type of geometry for this feature, as an <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeomType" title="django.contrib.gis.gdal.OGRGeomType"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeomType</span></code></a>
object. This will be the same for all features in a given layer and is
equivalent to the <a class="reference internal" href="#django.contrib.gis.gdal.Layer.geom_type" title="django.contrib.gis.gdal.Layer.geom_type"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Layer.geom_type</span></code></a> property of the <a class="reference internal" href="#django.contrib.gis.gdal.Layer" title="django.contrib.gis.gdal.Layer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Layer</span></code></a>
object the feature came from.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Feature.num_fields">
<code class="descname">num_fields</code><a class="headerlink" href="#django.contrib.gis.gdal.Feature.num_fields" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the number of fields of data associated with the feature. This will
be the same for all features in a given layer and is equivalent to the
<a class="reference internal" href="#django.contrib.gis.gdal.Layer.num_fields" title="django.contrib.gis.gdal.Layer.num_fields"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Layer.num_fields</span></code></a> property of the <a class="reference internal" href="#django.contrib.gis.gdal.Layer" title="django.contrib.gis.gdal.Layer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Layer</span></code></a> object the feature
came from.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Feature.fields">
<code class="descname">fields</code><a class="headerlink" href="#django.contrib.gis.gdal.Feature.fields" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a list of the names of the fields of data associated with the
feature. This will be the same for all features in a given layer and is
equivalent to the <a class="reference internal" href="#django.contrib.gis.gdal.Layer.fields" title="django.contrib.gis.gdal.Layer.fields"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Layer.fields</span></code></a> property of the <a class="reference internal" href="#django.contrib.gis.gdal.Layer" title="django.contrib.gis.gdal.Layer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Layer</span></code></a>
object the feature came from.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Feature.fid">
<code class="descname">fid</code><a class="headerlink" href="#django.contrib.gis.gdal.Feature.fid" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the feature identifier within the layer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="o">.</span><span class="n">fid</span>
<span class="go">0</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Feature.layer_name">
<code class="descname">layer_name</code><a class="headerlink" href="#django.contrib.gis.gdal.Feature.layer_name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the name of the <a class="reference internal" href="#django.contrib.gis.gdal.Layer" title="django.contrib.gis.gdal.Layer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Layer</span></code></a> that the feature came from. This
will be the same for all features in a given layer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="o">.</span><span class="n">layer_name</span>
<span class="go">&#39;cities&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Feature.index">
<code class="descname">index</code><a class="headerlink" href="#django.contrib.gis.gdal.Feature.index" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>A method that returns the index of the given field name. This will be the
same for all features in a given layer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">&#39;Population&#39;</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="s-field">
<span id="field"></span><h3><code class="docutils literal notranslate"><span class="pre">Field</span></code><a class="headerlink" href="#field" title="永久链接至标题">¶</a></h3>
<dl class="class">
<dt id="django.contrib.gis.gdal.Field">
<em class="property">class </em><code class="descname">Field</code><a class="headerlink" href="#django.contrib.gis.gdal.Field" title="永久链接至目标">¶</a></dt>
<dd><dl class="attribute">
<dt id="django.contrib.gis.gdal.Field.name">
<code class="descname">name</code><a class="headerlink" href="#django.contrib.gis.gdal.Field.name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the name of this field:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="p">[</span><span class="s1">&#39;Name&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;Name&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Field.type">
<code class="descname">type</code><a class="headerlink" href="#django.contrib.gis.gdal.Field.type" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the OGR type of this field, as an integer. The <code class="docutils literal notranslate"><span class="pre">FIELD_CLASSES</span></code>
dictionary maps these values onto subclasses of <code class="docutils literal notranslate"><span class="pre">Field</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="p">[</span><span class="s1">&#39;Density&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">type</span>
<span class="go">2</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Field.type_name">
<code class="descname">type_name</code><a class="headerlink" href="#django.contrib.gis.gdal.Field.type_name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a string with the name of the data type of this field:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="p">[</span><span class="s1">&#39;Name&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">type_name</span>
<span class="go">&#39;String&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Field.value">
<code class="descname">value</code><a class="headerlink" href="#django.contrib.gis.gdal.Field.value" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the value of this field. The <code class="docutils literal notranslate"><span class="pre">Field</span></code> class itself returns the
value as a string, but each subclass returns the value in the most
appropriate form:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="p">[</span><span class="s1">&#39;Population&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span>
<span class="go">102121</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Field.width">
<code class="descname">width</code><a class="headerlink" href="#django.contrib.gis.gdal.Field.width" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the width of this field:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="p">[</span><span class="s1">&#39;Name&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">width</span>
<span class="go">80</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Field.precision">
<code class="descname">precision</code><a class="headerlink" href="#django.contrib.gis.gdal.Field.precision" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the numeric precision of this field. This is meaningless (and set
to zero) for non-numeric fields:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="p">[</span><span class="s1">&#39;Density&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">precision</span>
<span class="go">15</span>
</pre></div>
</div>
<dl class="method">
<dt id="django.contrib.gis.gdal.Field.as_double">
<code class="descname">as_double</code>()<a class="headerlink" href="#django.contrib.gis.gdal.Field.as_double" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the value of the field as a double (float):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="p">[</span><span class="s1">&#39;Density&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">as_double</span><span class="p">()</span>
<span class="go">874.7</span>
</pre></div>
</div>
<dl class="method">
<dt id="django.contrib.gis.gdal.Field.as_int">
<code class="descname">as_int</code>()<a class="headerlink" href="#django.contrib.gis.gdal.Field.as_int" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the value of the field as an integer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="p">[</span><span class="s1">&#39;Population&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">as_int</span><span class="p">()</span>
<span class="go">102121</span>
</pre></div>
</div>
<dl class="method">
<dt id="django.contrib.gis.gdal.Field.as_string">
<code class="descname">as_string</code>()<a class="headerlink" href="#django.contrib.gis.gdal.Field.as_string" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the value of the field as a string:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="p">[</span><span class="s1">&#39;Name&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">as_string</span><span class="p">()</span>
<span class="go">&#39;Pueblo&#39;</span>
</pre></div>
</div>
<dl class="method">
<dt id="django.contrib.gis.gdal.Field.as_datetime">
<code class="descname">as_datetime</code>()<a class="headerlink" href="#django.contrib.gis.gdal.Field.as_datetime" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the value of the field as a tuple of date and time components:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="p">[</span><span class="s1">&#39;Created&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">as_datetime</span><span class="p">()</span>
<span class="go">(c_long(1999), c_long(5), c_long(23), c_long(0), c_long(0), c_long(0), c_long(0))</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="s-driver">
<span id="driver"></span><h3><code class="docutils literal notranslate"><span class="pre">Driver</span></code><a class="headerlink" href="#driver" title="永久链接至标题">¶</a></h3>
<dl class="class">
<dt id="django.contrib.gis.gdal.Driver">
<em class="property">class </em><code class="descname">Driver</code>(<em>dr_input</em>)<a class="headerlink" href="#django.contrib.gis.gdal.Driver" title="永久链接至目标">¶</a></dt>
<dd><p>The <code class="docutils literal notranslate"><span class="pre">Driver</span></code> class is used internally to wrap an OGR <a class="reference internal" href="#django.contrib.gis.gdal.DataSource" title="django.contrib.gis.gdal.DataSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">DataSource</span></code></a>
driver.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Driver.driver_count">
<code class="descname">driver_count</code><a class="headerlink" href="#django.contrib.gis.gdal.Driver.driver_count" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the number of OGR vector drivers currently registered.</p>
</dd></dl>

</div>
</div>
<div class="section" id="s-ogr-geometries">
<span id="ogr-geometries"></span><h2>OGR Geometries<a class="headerlink" href="#ogr-geometries" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-ogrgeometry">
<span id="ogrgeometry"></span><h3><code class="docutils literal notranslate"><span class="pre">OGRGeometry</span></code><a class="headerlink" href="#ogrgeometry" title="永久链接至标题">¶</a></h3>
<p><a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> objects share similar functionality with
<a class="reference internal" href="geos.html#django.contrib.gis.geos.GEOSGeometry" title="django.contrib.gis.geos.GEOSGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">GEOSGeometry</span></code></a> objects and are thin wrappers
around OGR's internal geometry representation. Thus, they allow for more
efficient access to data when using <a class="reference internal" href="#django.contrib.gis.gdal.DataSource" title="django.contrib.gis.gdal.DataSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">DataSource</span></code></a>. Unlike its GEOS
counterpart, <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> supports spatial reference systems and
coordinate transformation:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.contrib.gis.gdal</span> <span class="kn">import</span> <span class="n">OGRGeometry</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">polygon</span> <span class="o">=</span> <span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;POLYGON((0 0, 5 0, 5 5, 0 5))&#39;</span><span class="p">)</span>
</pre></div>
</div>
<dl class="class">
<dt id="django.contrib.gis.gdal.OGRGeometry">
<em class="property">class </em><code class="descname">OGRGeometry</code>(<em>geom_input</em>, <em>srs=None</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry" title="永久链接至目标">¶</a></dt>
<dd><p>This object is a wrapper for the <a class="reference external" href="https://gdal.org/api/ogrgeometry_cpp.html#ogrgeometry-class">OGR Geometry</a> class. These objects are
instantiated directly from the given <code class="docutils literal notranslate"><span class="pre">geom_input</span></code> parameter, which may be
a string containing WKT, HEX, GeoJSON, a <code class="docutils literal notranslate"><span class="pre">buffer</span></code> containing WKB data, or
an <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeomType" title="django.contrib.gis.gdal.OGRGeomType"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeomType</span></code></a> object. These objects are also returned from the
<a class="reference internal" href="#django.contrib.gis.gdal.Feature.geom" title="django.contrib.gis.gdal.Feature.geom"><code class="xref py py-class docutils literal notranslate"><span class="pre">Feature.geom</span></code></a> attribute, when reading vector data from
<a class="reference internal" href="#django.contrib.gis.gdal.Layer" title="django.contrib.gis.gdal.Layer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Layer</span></code></a> (which is in turn a part of a <a class="reference internal" href="#django.contrib.gis.gdal.DataSource" title="django.contrib.gis.gdal.DataSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">DataSource</span></code></a>).</p>
<dl class="classmethod">
<dt id="django.contrib.gis.gdal.OGRGeometry.from_gml">
<em class="property">classmethod </em><code class="descname">from_gml</code>(<em>gml_string</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.from_gml" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Constructs an <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> from the given GML string.</p>
<dl class="classmethod">
<dt id="django.contrib.gis.gdal.OGRGeometry.from_bbox">
<em class="property">classmethod </em><code class="descname">from_bbox</code>(<em>bbox</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.from_bbox" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Constructs a <a class="reference internal" href="#django.contrib.gis.gdal.Polygon" title="django.contrib.gis.gdal.Polygon"><code class="xref py py-class docutils literal notranslate"><span class="pre">Polygon</span></code></a> from the given bounding-box (a 4-tuple).</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.__len__">
<code class="descname">__len__</code>()<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.__len__" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the number of points in a <a class="reference internal" href="#django.contrib.gis.gdal.LineString" title="django.contrib.gis.gdal.LineString"><code class="xref py py-class docutils literal notranslate"><span class="pre">LineString</span></code></a>, the number of rings
in a <a class="reference internal" href="#django.contrib.gis.gdal.Polygon" title="django.contrib.gis.gdal.Polygon"><code class="xref py py-class docutils literal notranslate"><span class="pre">Polygon</span></code></a>, or the number of geometries in a
<a class="reference internal" href="#django.contrib.gis.gdal.GeometryCollection" title="django.contrib.gis.gdal.GeometryCollection"><code class="xref py py-class docutils literal notranslate"><span class="pre">GeometryCollection</span></code></a>. Not applicable to other geometry types.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.__iter__">
<code class="descname">__iter__</code>()<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.__iter__" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Iterates over the points in a <a class="reference internal" href="#django.contrib.gis.gdal.LineString" title="django.contrib.gis.gdal.LineString"><code class="xref py py-class docutils literal notranslate"><span class="pre">LineString</span></code></a>, the rings in a
<a class="reference internal" href="#django.contrib.gis.gdal.Polygon" title="django.contrib.gis.gdal.Polygon"><code class="xref py py-class docutils literal notranslate"><span class="pre">Polygon</span></code></a>, or the geometries in a <a class="reference internal" href="#django.contrib.gis.gdal.GeometryCollection" title="django.contrib.gis.gdal.GeometryCollection"><code class="xref py py-class docutils literal notranslate"><span class="pre">GeometryCollection</span></code></a>.
Not applicable to other geometry types.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.__getitem__">
<code class="descname">__getitem__</code>()<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.__getitem__" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the point at the specified index for a <a class="reference internal" href="#django.contrib.gis.gdal.LineString" title="django.contrib.gis.gdal.LineString"><code class="xref py py-class docutils literal notranslate"><span class="pre">LineString</span></code></a>, the
interior ring at the specified index for a <a class="reference internal" href="#django.contrib.gis.gdal.Polygon" title="django.contrib.gis.gdal.Polygon"><code class="xref py py-class docutils literal notranslate"><span class="pre">Polygon</span></code></a>, or the geometry
at the specified index in a <a class="reference internal" href="#django.contrib.gis.gdal.GeometryCollection" title="django.contrib.gis.gdal.GeometryCollection"><code class="xref py py-class docutils literal notranslate"><span class="pre">GeometryCollection</span></code></a>. Not applicable to
other geometry types.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.dimension">
<code class="descname">dimension</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.dimension" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the number of coordinated dimensions of the geometry, i.e. 0
for points, 1 for lines, and so forth:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;&gt;</span> <span class="n">polygon</span><span class="o">.</span><span class="n">dimension</span>
<span class="mi">2</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.coord_dim">
<code class="descname">coord_dim</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.coord_dim" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns or sets the coordinate dimension of this geometry. For example, the
value would be 2 for two-dimensional geometries.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.geom_count">
<code class="descname">geom_count</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.geom_count" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the number of elements in this geometry:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">polygon</span><span class="o">.</span><span class="n">geom_count</span>
<span class="go">1</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.point_count">
<code class="descname">point_count</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.point_count" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the number of points used to describe this geometry:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">polygon</span><span class="o">.</span><span class="n">point_count</span>
<span class="go">4</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.num_points">
<code class="descname">num_points</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.num_points" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Alias for <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry.point_count" title="django.contrib.gis.gdal.OGRGeometry.point_count"><code class="xref py py-attr docutils literal notranslate"><span class="pre">point_count</span></code></a>.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.num_coords">
<code class="descname">num_coords</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.num_coords" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Alias for <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry.point_count" title="django.contrib.gis.gdal.OGRGeometry.point_count"><code class="xref py py-attr docutils literal notranslate"><span class="pre">point_count</span></code></a>.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.geom_type">
<code class="descname">geom_type</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.geom_type" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the type of this geometry, as an <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeomType" title="django.contrib.gis.gdal.OGRGeomType"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeomType</span></code></a> object.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.geom_name">
<code class="descname">geom_name</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.geom_name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the name of the type of this geometry:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">polygon</span><span class="o">.</span><span class="n">geom_name</span>
<span class="go">&#39;POLYGON&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.area">
<code class="descname">area</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.area" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the area of this geometry, or 0 for geometries that do not contain
an area:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">polygon</span><span class="o">.</span><span class="n">area</span>
<span class="go">25.0</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.envelope">
<code class="descname">envelope</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.envelope" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the envelope of this geometry, as an <a class="reference internal" href="#django.contrib.gis.gdal.Envelope" title="django.contrib.gis.gdal.Envelope"><code class="xref py py-class docutils literal notranslate"><span class="pre">Envelope</span></code></a> object.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.extent">
<code class="descname">extent</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.extent" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the envelope of this geometry as a 4-tuple, instead of as an
<a class="reference internal" href="#django.contrib.gis.gdal.Envelope" title="django.contrib.gis.gdal.Envelope"><code class="xref py py-class docutils literal notranslate"><span class="pre">Envelope</span></code></a> object:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">point</span><span class="o">.</span><span class="n">extent</span>
<span class="go">(0.0, 0.0, 5.0, 5.0)</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.srs">
<code class="descname">srs</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.srs" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>This property controls the spatial reference for this geometry, or
<code class="docutils literal notranslate"><span class="pre">None</span></code> if no spatial reference system has been assigned to it.
If assigned, accessing this property returns a <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a>
object.  It may be set with another <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> object,
or any input that <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> accepts. Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">city</span><span class="o">.</span><span class="n">geom</span><span class="o">.</span><span class="n">srs</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;GCS_WGS_1984&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.srid">
<code class="descname">srid</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.srid" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns or sets the spatial reference identifier corresponding to
<a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> of this geometry.  Returns <code class="docutils literal notranslate"><span class="pre">None</span></code> if
there is no spatial reference information associated with this
geometry, or if an SRID cannot be determined.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.geos">
<code class="descname">geos</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.geos" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a <a class="reference internal" href="geos.html#django.contrib.gis.geos.GEOSGeometry" title="django.contrib.gis.geos.GEOSGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">GEOSGeometry</span></code></a> object
corresponding to this geometry.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.gml">
<code class="descname">gml</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.gml" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a string representation of this geometry in GML format:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;POINT(1 2)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">gml</span>
<span class="go">&#39;&lt;gml:Point&gt;&lt;gml:coordinates&gt;1,2&lt;/gml:coordinates&gt;&lt;/gml:Point&gt;&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.hex">
<code class="descname">hex</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.hex" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a string representation of this geometry in HEX WKB format:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;POINT(1 2)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">hex</span>
<span class="go">&#39;0101000000000000000000F03F0000000000000040&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.json">
<code class="descname">json</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.json" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a string representation of this geometry in JSON format:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;POINT(1 2)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">json</span>
<span class="go">&#39;{ &quot;type&quot;: &quot;Point&quot;, &quot;coordinates&quot;: [ 1.000000, 2.000000 ] }&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.kml">
<code class="descname">kml</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.kml" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a string representation of this geometry in KML format.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.wkb_size">
<code class="descname">wkb_size</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.wkb_size" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the size of the WKB buffer needed to hold a WKB representation
of this geometry:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;POINT(1 2)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">wkb_size</span>
<span class="go">21</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.wkb">
<code class="descname">wkb</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.wkb" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a <code class="docutils literal notranslate"><span class="pre">buffer</span></code> containing a WKB representation of this geometry.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.wkt">
<code class="descname">wkt</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.wkt" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a string representation of this geometry in WKT format.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.ewkt">
<code class="descname">ewkt</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.ewkt" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the EWKT representation of this geometry.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.clone">
<code class="descname">clone</code>()<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.clone" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a new <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> clone of this geometry object.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.close_rings">
<code class="descname">close_rings</code>()<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.close_rings" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>If there are any rings within this geometry that have not been closed,
this routine will do so by adding the starting point to the end:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">triangle</span> <span class="o">=</span> <span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;LINEARRING (0 0,0 1,1 0)&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">triangle</span><span class="o">.</span><span class="n">close_rings</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">triangle</span><span class="o">.</span><span class="n">wkt</span>
<span class="go">&#39;LINEARRING (0 0,0 1,1 0,0 0)&#39;</span>
</pre></div>
</div>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.transform">
<code class="descname">transform</code>(<em>coord_trans</em>, <em>clone=False</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.transform" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Transforms this geometry to a different spatial reference system. May take
a <a class="reference internal" href="#django.contrib.gis.gdal.CoordTransform" title="django.contrib.gis.gdal.CoordTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">CoordTransform</span></code></a> object, a <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> object, or
any other input accepted by <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> (including spatial
reference WKT and PROJ strings, or an integer SRID).</p>
<p>By default nothing is returned and the geometry is transformed in-place.
However, if the <code class="docutils literal notranslate"><span class="pre">clone</span></code> keyword is set to <code class="docutils literal notranslate"><span class="pre">True</span></code> then a transformed
clone of this geometry is returned instead.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.intersects">
<code class="descname">intersects</code>(<em>other</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.intersects" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this geometry intersects the other, otherwise returns
<code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.equals">
<code class="descname">equals</code>(<em>other</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.equals" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this geometry is equivalent to the other, otherwise
returns <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.disjoint">
<code class="descname">disjoint</code>(<em>other</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.disjoint" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this geometry is spatially disjoint to (i.e. does
not intersect) the other, otherwise returns <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.touches">
<code class="descname">touches</code>(<em>other</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.touches" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this geometry touches the other, otherwise returns
<code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.crosses">
<code class="descname">crosses</code>(<em>other</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.crosses" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this geometry crosses the other, otherwise returns
<code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.within">
<code class="descname">within</code>(<em>other</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.within" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this geometry is contained within the other, otherwise
returns <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.contains">
<code class="descname">contains</code>(<em>other</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.contains" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this geometry contains the other, otherwise returns
<code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.overlaps">
<code class="descname">overlaps</code>(<em>other</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.overlaps" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this geometry overlaps the other, otherwise returns
<code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.boundary">
<code class="descname">boundary</code>()<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.boundary" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>The boundary of this geometry, as a new <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> object.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.convex_hull">
<code class="descname">convex_hull</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.convex_hull" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>The smallest convex polygon that contains this geometry, as a new
<a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> object.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.difference">
<code class="descname">difference</code>()<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.difference" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the region consisting of the difference of this geometry and
the other, as a new <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> object.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.intersection">
<code class="descname">intersection</code>()<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.intersection" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the region consisting of the intersection of this geometry and
the other, as a new <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> object.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.sym_difference">
<code class="descname">sym_difference</code>()<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.sym_difference" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the region consisting of the symmetric difference of this
geometry and the other, as a new <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> object.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.OGRGeometry.union">
<code class="descname">union</code>()<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.union" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the region consisting of the union of this geometry and
the other, as a new <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry" title="django.contrib.gis.gdal.OGRGeometry"><code class="xref py py-class docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a> object.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.tuple">
<code class="descname">tuple</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.tuple" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the coordinates of a point geometry as a tuple, the
coordinates of a line geometry as a tuple of tuples, and so forth:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;POINT (1 2)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">tuple</span>
<span class="go">(1.0, 2.0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;LINESTRING (1 2,3 4)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">tuple</span>
<span class="go">((1.0, 2.0), (3.0, 4.0))</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeometry.coords">
<code class="descname">coords</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeometry.coords" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>An alias for <a class="reference internal" href="#django.contrib.gis.gdal.OGRGeometry.tuple" title="django.contrib.gis.gdal.OGRGeometry.tuple"><code class="xref py py-attr docutils literal notranslate"><span class="pre">tuple</span></code></a>.</p>
</dd></dl>

<dl class="class">
<dt id="django.contrib.gis.gdal.Point">
<em class="property">class </em><code class="descname">Point</code><a class="headerlink" href="#django.contrib.gis.gdal.Point" title="永久链接至目标">¶</a></dt>
<dd><dl class="attribute">
<dt id="django.contrib.gis.gdal.Point.x">
<code class="descname">x</code><a class="headerlink" href="#django.contrib.gis.gdal.Point.x" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the X coordinate of this point:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;POINT (1 2)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">x</span>
<span class="go">1.0</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Point.y">
<code class="descname">y</code><a class="headerlink" href="#django.contrib.gis.gdal.Point.y" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the Y coordinate of this point:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;POINT (1 2)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">y</span>
<span class="go">2.0</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Point.z">
<code class="descname">z</code><a class="headerlink" href="#django.contrib.gis.gdal.Point.z" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the Z coordinate of this point, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the point does not
have a Z coordinate:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;POINT (1 2 3)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">z</span>
<span class="go">3.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="class">
<dt id="django.contrib.gis.gdal.LineString">
<em class="property">class </em><code class="descname">LineString</code><a class="headerlink" href="#django.contrib.gis.gdal.LineString" title="永久链接至目标">¶</a></dt>
<dd><dl class="attribute">
<dt id="django.contrib.gis.gdal.LineString.x">
<code class="descname">x</code><a class="headerlink" href="#django.contrib.gis.gdal.LineString.x" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a list of X coordinates in this line:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;LINESTRING (1 2,3 4)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">x</span>
<span class="go">[1.0, 3.0]</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.LineString.y">
<code class="descname">y</code><a class="headerlink" href="#django.contrib.gis.gdal.LineString.y" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a list of Y coordinates in this line:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;LINESTRING (1 2,3 4)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">y</span>
<span class="go">[2.0, 4.0]</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.LineString.z">
<code class="descname">z</code><a class="headerlink" href="#django.contrib.gis.gdal.LineString.z" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a list of Z coordinates in this line, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the line does
not have Z coordinates:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">OGRGeometry</span><span class="p">(</span><span class="s1">&#39;LINESTRING (1 2 3,4 5 6)&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">z</span>
<span class="go">[3.0, 6.0]</span>
</pre></div>
</div>
</dd></dl>

<dl class="class">
<dt id="django.contrib.gis.gdal.Polygon">
<em class="property">class </em><code class="descname">Polygon</code><a class="headerlink" href="#django.contrib.gis.gdal.Polygon" title="永久链接至目标">¶</a></dt>
<dd><dl class="attribute">
<dt id="django.contrib.gis.gdal.Polygon.shell">
<code class="descname">shell</code><a class="headerlink" href="#django.contrib.gis.gdal.Polygon.shell" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the shell or exterior ring of this polygon, as a <code class="docutils literal notranslate"><span class="pre">LinearRing</span></code>
geometry.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Polygon.exterior_ring">
<code class="descname">exterior_ring</code><a class="headerlink" href="#django.contrib.gis.gdal.Polygon.exterior_ring" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>An alias for <a class="reference internal" href="#django.contrib.gis.gdal.Polygon.shell" title="django.contrib.gis.gdal.Polygon.shell"><code class="xref py py-attr docutils literal notranslate"><span class="pre">shell</span></code></a>.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Polygon.centroid">
<code class="descname">centroid</code><a class="headerlink" href="#django.contrib.gis.gdal.Polygon.centroid" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a <a class="reference internal" href="#django.contrib.gis.gdal.Point" title="django.contrib.gis.gdal.Point"><code class="xref py py-class docutils literal notranslate"><span class="pre">Point</span></code></a> representing the centroid of this polygon.</p>
</dd></dl>

<dl class="class">
<dt id="django.contrib.gis.gdal.GeometryCollection">
<em class="property">class </em><code class="descname">GeometryCollection</code><a class="headerlink" href="#django.contrib.gis.gdal.GeometryCollection" title="永久链接至目标">¶</a></dt>
<dd><dl class="method">
<dt id="django.contrib.gis.gdal.GeometryCollection.add">
<code class="descname">add</code>(<em>geom</em>)<a class="headerlink" href="#django.contrib.gis.gdal.GeometryCollection.add" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Adds a geometry to this geometry collection. Not applicable to other
geometry types.</p>
</dd></dl>

</div>
<div class="section" id="s-ogrgeomtype">
<span id="ogrgeomtype"></span><h3><code class="docutils literal notranslate"><span class="pre">OGRGeomType</span></code><a class="headerlink" href="#ogrgeomtype" title="永久链接至标题">¶</a></h3>
<dl class="class">
<dt id="django.contrib.gis.gdal.OGRGeomType">
<em class="property">class </em><code class="descname">OGRGeomType</code>(<em>type_input</em>)<a class="headerlink" href="#django.contrib.gis.gdal.OGRGeomType" title="永久链接至目标">¶</a></dt>
<dd><p>This class allows for the representation of an OGR geometry type
in any of several ways:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.contrib.gis.gdal</span> <span class="kn">import</span> <span class="n">OGRGeomType</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gt1</span> <span class="o">=</span> <span class="n">OGRGeomType</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>             <span class="c1"># Using an integer for the type</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gt2</span> <span class="o">=</span> <span class="n">OGRGeomType</span><span class="p">(</span><span class="s1">&#39;Polygon&#39;</span><span class="p">)</span>     <span class="c1"># Using a string</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gt3</span> <span class="o">=</span> <span class="n">OGRGeomType</span><span class="p">(</span><span class="s1">&#39;POLYGON&#39;</span><span class="p">)</span>     <span class="c1"># It&#39;s case-insensitive</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">gt1</span> <span class="o">==</span> <span class="mi">3</span><span class="p">,</span> <span class="n">gt1</span> <span class="o">==</span> <span class="s1">&#39;Polygon&#39;</span><span class="p">)</span> <span class="c1"># Equivalence works w/non-OGRGeomType objects</span>
<span class="go">True True</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeomType.name">
<code class="descname">name</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeomType.name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a short-hand string form of the OGR Geometry type:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">gt1</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;Polygon&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeomType.num">
<code class="descname">num</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeomType.num" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the number corresponding to the OGR geometry type:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">gt1</span><span class="o">.</span><span class="n">num</span>
<span class="go">3</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.OGRGeomType.django">
<code class="descname">django</code><a class="headerlink" href="#django.contrib.gis.gdal.OGRGeomType.django" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the Django field type (a subclass of GeometryField) to use for
storing this OGR type, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if there is no appropriate Django type:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">gt1</span><span class="o">.</span><span class="n">django</span>
<span class="go">&#39;PolygonField&#39;</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="s-envelope">
<span id="envelope"></span><h3><code class="docutils literal notranslate"><span class="pre">Envelope</span></code><a class="headerlink" href="#envelope" title="永久链接至标题">¶</a></h3>
<dl class="class">
<dt id="django.contrib.gis.gdal.Envelope">
<em class="property">class </em><code class="descname">Envelope</code>(<em>*args</em>)<a class="headerlink" href="#django.contrib.gis.gdal.Envelope" title="永久链接至目标">¶</a></dt>
<dd><p>Represents an OGR Envelope structure that contains the minimum and maximum
X, Y coordinates for a rectangle bounding box. The naming of the variables
is compatible with the OGR Envelope C structure.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Envelope.min_x">
<code class="descname">min_x</code><a class="headerlink" href="#django.contrib.gis.gdal.Envelope.min_x" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>The value of the minimum X coordinate.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Envelope.min_y">
<code class="descname">min_y</code><a class="headerlink" href="#django.contrib.gis.gdal.Envelope.min_y" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>The value of the maximum X coordinate.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Envelope.max_x">
<code class="descname">max_x</code><a class="headerlink" href="#django.contrib.gis.gdal.Envelope.max_x" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>The value of the minimum Y coordinate.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Envelope.max_y">
<code class="descname">max_y</code><a class="headerlink" href="#django.contrib.gis.gdal.Envelope.max_y" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>The value of the maximum Y coordinate.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Envelope.ur">
<code class="descname">ur</code><a class="headerlink" href="#django.contrib.gis.gdal.Envelope.ur" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>The upper-right coordinate, as a tuple.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Envelope.ll">
<code class="descname">ll</code><a class="headerlink" href="#django.contrib.gis.gdal.Envelope.ll" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>The lower-left coordinate, as a tuple.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Envelope.tuple">
<code class="descname">tuple</code><a class="headerlink" href="#django.contrib.gis.gdal.Envelope.tuple" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>A tuple representing the envelope.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.Envelope.wkt">
<code class="descname">wkt</code><a class="headerlink" href="#django.contrib.gis.gdal.Envelope.wkt" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>A string representing this envelope as a polygon in WKT format.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.Envelope.expand_to_include">
<code class="descname">expand_to_include</code>(<em>*args</em>)<a class="headerlink" href="#django.contrib.gis.gdal.Envelope.expand_to_include" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

</dd></dl>

</div>
</div>
<div class="section" id="s-coordinate-system-objects">
<span id="coordinate-system-objects"></span><h2>Coordinate System Objects<a class="headerlink" href="#coordinate-system-objects" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-spatialreference">
<span id="spatialreference"></span><h3><code class="docutils literal notranslate"><span class="pre">SpatialReference</span></code><a class="headerlink" href="#spatialreference" title="永久链接至标题">¶</a></h3>
<dl class="class">
<dt id="django.contrib.gis.gdal.SpatialReference">
<em class="property">class </em><code class="descname">SpatialReference</code>(<em>srs_input</em>)<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference" title="永久链接至目标">¶</a></dt>
<dd><p>Spatial reference objects are initialized on the given <code class="docutils literal notranslate"><span class="pre">srs_input</span></code>,
which may be one of the following:</p>
<ul class="simple">
<li>OGC Well Known Text (WKT) (a string)</li>
<li>EPSG code (integer or string)</li>
<li>PROJ string</li>
<li>A shorthand string for well-known standards (<code class="docutils literal notranslate"><span class="pre">'WGS84'</span></code>, <code class="docutils literal notranslate"><span class="pre">'WGS72'</span></code>,
<code class="docutils literal notranslate"><span class="pre">'NAD27'</span></code>, <code class="docutils literal notranslate"><span class="pre">'NAD83'</span></code>)</li>
</ul>
<p>举例：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">wgs84</span> <span class="o">=</span> <span class="n">SpatialReference</span><span class="p">(</span><span class="s1">&#39;WGS84&#39;</span><span class="p">)</span> <span class="c1"># shorthand string</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">wgs84</span> <span class="o">=</span> <span class="n">SpatialReference</span><span class="p">(</span><span class="mi">4326</span><span class="p">)</span> <span class="c1"># EPSG code</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">wgs84</span> <span class="o">=</span> <span class="n">SpatialReference</span><span class="p">(</span><span class="s1">&#39;EPSG:4326&#39;</span><span class="p">)</span> <span class="c1"># EPSG string</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">proj</span> <span class="o">=</span> <span class="s1">&#39;+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs &#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">wgs84</span> <span class="o">=</span> <span class="n">SpatialReference</span><span class="p">(</span><span class="n">proj</span><span class="p">)</span> <span class="c1"># PROJ string</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">wgs84</span> <span class="o">=</span> <span class="n">SpatialReference</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;GEOGCS[&quot;WGS 84&quot;,</span>
<span class="go">DATUM[&quot;WGS_1984&quot;,</span>
<span class="go">     SPHEROID[&quot;WGS 84&quot;,6378137,298.257223563,</span>
<span class="go">         AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],</span>
<span class="go">     AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],</span>
<span class="go"> PRIMEM[&quot;Greenwich&quot;,0,</span>
<span class="go">     AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]],</span>
<span class="go"> UNIT[&quot;degree&quot;,0.01745329251994328,</span>
<span class="go">     AUTHORITY[&quot;EPSG&quot;,&quot;9122&quot;]],</span>
<span class="go"> AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]&quot;&quot;&quot;) # OGC WKT</span>
</pre></div>
</div>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.__getitem__">
<code class="descname">__getitem__</code>(<em>target</em>)<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.__getitem__" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the value of the given string attribute node, <code class="docutils literal notranslate"><span class="pre">None</span></code> if the node
doesn't exist. Can also take a tuple as a parameter, (target, child), where
child is the index of the attribute in the WKT. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">wkt</span> <span class="o">=</span> <span class="s1">&#39;GEOGCS[&quot;WGS 84&quot;, DATUM[&quot;WGS_1984, ... AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">srs</span> <span class="o">=</span> <span class="n">SpatialReference</span><span class="p">(</span><span class="n">wkt</span><span class="p">)</span> <span class="c1"># could also use &#39;WGS84&#39;, or 4326</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">srs</span><span class="p">[</span><span class="s1">&#39;GEOGCS&#39;</span><span class="p">])</span>
<span class="go">WGS 84</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">srs</span><span class="p">[</span><span class="s1">&#39;DATUM&#39;</span><span class="p">])</span>
<span class="go">WGS_1984</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">srs</span><span class="p">[</span><span class="s1">&#39;AUTHORITY&#39;</span><span class="p">])</span>
<span class="go">EPSG</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">srs</span><span class="p">[</span><span class="s1">&#39;AUTHORITY&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="c1"># The authority value</span>
<span class="go">4326</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">srs</span><span class="p">[</span><span class="s1">&#39;TOWGS84&#39;</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span> <span class="c1"># the fourth value in this wkt</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">srs</span><span class="p">[</span><span class="s1">&#39;UNIT|AUTHORITY&#39;</span><span class="p">])</span> <span class="c1"># For the units authority, have to use the pipe symbol.</span>
<span class="go">EPSG</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">srs</span><span class="p">[</span><span class="s1">&#39;UNIT|AUTHORITY&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="c1"># The authority value for the units</span>
<span class="go">9122</span>
</pre></div>
</div>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.attr_value">
<code class="descname">attr_value</code>(<em>target</em>, <em>index=0</em>)<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.attr_value" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>The attribute value for the given target node (e.g. <code class="docutils literal notranslate"><span class="pre">'PROJCS'</span></code>).
The index keyword specifies an index of the child node to return.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.auth_name">
<code class="descname">auth_name</code>(<em>target</em>)<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.auth_name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the authority name for the given string target node.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.auth_code">
<code class="descname">auth_code</code>(<em>target</em>)<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.auth_code" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the authority code for the given string target node.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.clone">
<code class="descname">clone</code>()<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.clone" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a clone of this spatial reference object.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.identify_epsg">
<code class="descname">identify_epsg</code>()<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.identify_epsg" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>This method inspects the WKT of this <code class="docutils literal notranslate"><span class="pre">SpatialReference</span></code> and will add EPSG
authority nodes where an EPSG identifier is applicable.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.from_esri">
<code class="descname">from_esri</code>()<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.from_esri" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Morphs this SpatialReference from ESRI's format to EPSG</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.to_esri">
<code class="descname">to_esri</code>()<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.to_esri" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Morphs this SpatialReference to ESRI's format.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.validate">
<code class="descname">validate</code>()<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.validate" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Checks to see if the given spatial reference is valid, if not
an exception will be raised.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.import_epsg">
<code class="descname">import_epsg</code>(<em>epsg</em>)<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.import_epsg" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Import spatial reference from EPSG code.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.import_proj">
<code class="descname">import_proj</code>(<em>proj</em>)<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.import_proj" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Import spatial reference from PROJ string.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.import_user_input">
<code class="descname">import_user_input</code>(<em>user_input</em>)<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.import_user_input" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.import_wkt">
<code class="descname">import_wkt</code>(<em>wkt</em>)<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.import_wkt" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Import spatial reference from WKT.</p>
<dl class="method">
<dt id="django.contrib.gis.gdal.SpatialReference.import_xml">
<code class="descname">import_xml</code>(<em>xml</em>)<a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.import_xml" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Import spatial reference from XML.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.name">
<code class="descname">name</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the name of this Spatial Reference.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.srid">
<code class="descname">srid</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.srid" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the SRID of top-level authority, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if undefined.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.linear_name">
<code class="descname">linear_name</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.linear_name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the name of the linear units.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.linear_units">
<code class="descname">linear_units</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.linear_units" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the value of the linear units.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.angular_name">
<code class="descname">angular_name</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.angular_name" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the name of the angular units.&quot;</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.angular_units">
<code class="descname">angular_units</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.angular_units" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the value of the angular units.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.units">
<code class="descname">units</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.units" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a 2-tuple of the units value and the units name and will
automatically determines whether to return the linear or angular units.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.ellipsoid">
<code class="descname">ellipsoid</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.ellipsoid" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns a tuple of the ellipsoid parameters for this spatial reference:
(semimajor axis, semiminor axis, and inverse flattening).</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.semi_major">
<code class="descname">semi_major</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.semi_major" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the semi major axis of the ellipsoid for this spatial reference.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.semi_minor">
<code class="descname">semi_minor</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.semi_minor" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the semi minor axis of the ellipsoid for this spatial reference.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.inverse_flattening">
<code class="descname">inverse_flattening</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.inverse_flattening" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the inverse flattening of the ellipsoid for this spatial reference.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.geographic">
<code class="descname">geographic</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.geographic" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this spatial reference is geographic (root node is
<code class="docutils literal notranslate"><span class="pre">GEOGCS</span></code>).</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.local">
<code class="descname">local</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.local" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this spatial reference is local (root node is
<code class="docutils literal notranslate"><span class="pre">LOCAL_CS</span></code>).</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.projected">
<code class="descname">projected</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.projected" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if this spatial reference is a projected coordinate system
(root node is <code class="docutils literal notranslate"><span class="pre">PROJCS</span></code>).</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.wkt">
<code class="descname">wkt</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.wkt" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the WKT representation of this spatial reference.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.pretty_wkt">
<code class="descname">pretty_wkt</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.pretty_wkt" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the 'pretty' representation of the WKT.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.proj">
<code class="descname">proj</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.proj" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the PROJ representation for this spatial reference.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.proj4">
<code class="descname">proj4</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.proj4" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Alias for <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference.proj" title="django.contrib.gis.gdal.SpatialReference.proj"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SpatialReference.proj</span></code></a>.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.SpatialReference.xml">
<code class="descname">xml</code><a class="headerlink" href="#django.contrib.gis.gdal.SpatialReference.xml" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Returns the XML representation of this spatial reference.</p>
</dd></dl>

</div>
<div class="section" id="s-coordtransform">
<span id="coordtransform"></span><h3><code class="docutils literal notranslate"><span class="pre">CoordTransform</span></code><a class="headerlink" href="#coordtransform" title="永久链接至标题">¶</a></h3>
<dl class="class">
<dt id="django.contrib.gis.gdal.CoordTransform">
<em class="property">class </em><code class="descname">CoordTransform</code>(<em>source</em>, <em>target</em>)<a class="headerlink" href="#django.contrib.gis.gdal.CoordTransform" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>Represents a coordinate system transform. It is initialized with two
<a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a>, representing the source and target coordinate
systems, respectively. These objects should be used when performing the same
coordinate transformation repeatedly on different geometries:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ct</span> <span class="o">=</span> <span class="n">CoordTransform</span><span class="p">(</span><span class="n">SpatialReference</span><span class="p">(</span><span class="s1">&#39;WGS84&#39;</span><span class="p">),</span> <span class="n">SpatialReference</span><span class="p">(</span><span class="s1">&#39;NAD83&#39;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">feat</span> <span class="ow">in</span> <span class="n">layer</span><span class="p">:</span>
<span class="gp">... </span>    <span class="n">geom</span> <span class="o">=</span> <span class="n">feat</span><span class="o">.</span><span class="n">geom</span> <span class="c1"># getting clone of feature geometry</span>
<span class="gp">... </span>    <span class="n">geom</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="n">ct</span><span class="p">)</span> <span class="c1"># transforming</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-raster-data-objects">
<span id="s-raster-data-source-objects"></span><span id="raster-data-objects"></span><span id="raster-data-source-objects"></span><h2>Raster Data Objects<a class="headerlink" href="#raster-data-objects" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-gdalraster">
<span id="gdalraster"></span><h3><code class="docutils literal notranslate"><span class="pre">GDALRaster</span></code><a class="headerlink" href="#gdalraster" title="永久链接至标题">¶</a></h3>
<p><a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster" title="django.contrib.gis.gdal.GDALRaster"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALRaster</span></code></a> is a wrapper for the GDAL raster source object that
supports reading data from a variety of GDAL-supported geospatial file
formats and data sources using a consistent interface.  Each
data source is represented by a <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster" title="django.contrib.gis.gdal.GDALRaster"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALRaster</span></code></a> object which contains
one or more layers of data named bands.  Each band, represented by a
<a class="reference internal" href="#django.contrib.gis.gdal.GDALBand" title="django.contrib.gis.gdal.GDALBand"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALBand</span></code></a> object, contains georeferenced image data. For example, an RGB
image is represented as three bands: one for red, one for green, and one for
blue.</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">For raster data there is no difference between a raster instance and its
data source. Unlike for the Geometry objects, <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster" title="django.contrib.gis.gdal.GDALRaster"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALRaster</span></code></a> objects are
always a data source. Temporary rasters can be instantiated in memory
using the corresponding driver, but they will be of the same class as file-based
raster sources.</p>
</div>
<dl class="class">
<dt id="django.contrib.gis.gdal.GDALRaster">
<em class="property">class </em><code class="descname">GDALRaster</code>(<em>ds_input</em>, <em>write=False</em>)<a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster" title="永久链接至目标">¶</a></dt>
<dd><p>The constructor for <code class="docutils literal notranslate"><span class="pre">GDALRaster</span></code> accepts two parameters. The first
parameter defines the raster source, and the second parameter defines if a
raster should be opened in write mode. For newly-created rasters, the second
parameter is ignored and the new raster is always created in write mode.</p>
<p>The first parameter can take three forms: a string representing a file
path, a dictionary with values defining a new raster, or a bytes object
representing a raster file.</p>
<p>If the input is a file path, the raster is opened from there. If the input
is raw data in a dictionary, the parameters <code class="docutils literal notranslate"><span class="pre">width</span></code>, <code class="docutils literal notranslate"><span class="pre">height</span></code>, and
<code class="docutils literal notranslate"><span class="pre">srid</span></code> are required. If the input is a bytes object, it will be opened
using a GDAL virtual filesystem.</p>
<p>For a detailed description of how to create rasters using dictionary input,
see <a class="reference internal" href="#gdal-raster-ds-input"><span class="std std-ref">Creating rasters from data</span></a>. For a detailed description of how to
create rasters in the virtual filesystem, see <a class="reference internal" href="#gdal-raster-vsimem"><span class="std std-ref">Using GDAL's Virtual Filesystem</span></a>.</p>
<p>The following example shows how rasters can be created from different input
sources (using the sample data from the GeoDjango tests; see also the
<a class="reference internal" href="#gdal-sample-data"><span class="std std-ref">样本数据</span></a> section).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.contrib.gis.gdal</span> <span class="kn">import</span> <span class="n">GDALRaster</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">(</span><span class="s1">&#39;/path/to/your/raster.tif&#39;</span><span class="p">,</span> <span class="n">write</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;/path/to/your/raster.tif&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">width</span><span class="p">,</span> <span class="n">rst</span><span class="o">.</span><span class="n">height</span>  <span class="c1"># This file has 163 x 174 pixels</span>
<span class="go">(163, 174)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span>  <span class="c1"># Creates an in-memory raster</span>
<span class="gp">... </span>    <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">,</span>
<span class="gp">... </span>    <span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
<span class="gp">... </span>    <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
<span class="gp">... </span>    <span class="s1">&#39;datatype&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="gp">... </span>    <span class="s1">&#39;bands&#39;</span><span class="p">:</span> <span class="p">[{</span>
<span class="gp">... </span>        <span class="s1">&#39;data&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span>
<span class="gp">... </span>        <span class="s1">&#39;offset&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
<span class="gp">... </span>        <span class="s1">&#39;size&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span>
<span class="gp">... </span>        <span class="s1">&#39;shape&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
<span class="gp">... </span>        <span class="s1">&#39;nodata_value&#39;</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span>
<span class="gp">... </span>    <span class="p">}]</span>
<span class="gp">... </span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">srs</span><span class="o">.</span><span class="n">srid</span>
<span class="go">4326</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">width</span><span class="p">,</span> <span class="n">rst</span><span class="o">.</span><span class="n">height</span>
<span class="go">(4, 4)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span><span class="p">()</span>
<span class="go">array([[5, 5, 5, 5],</span>
<span class="go">       [5, 2, 3, 5],</span>
<span class="go">       [5, 2, 3, 5],</span>
<span class="go">       [5, 5, 5, 5]], dtype=uint8)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst_file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s1">&#39;/path/to/your/raster.tif&#39;</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst_bytes</span> <span class="o">=</span> <span class="n">rst_file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">(</span><span class="n">rst_bytes</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">is_vsi_based</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">name</span>  <span class="c1"># Stored in a random path in the vsimem filesystem.</span>
<span class="go">&#39;/vsimem/da300bdb-129d-49a8-b336-e410a9428dad&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.name">
<code class="descname">name</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.name" title="永久链接至目标">¶</a></dt>
<dd><p>The name of the source which is equivalent to the input file path or the name
provided upon instantiation.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;myraster&#39;</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;myraster&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.driver">
<code class="descname">driver</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.driver" title="永久链接至目标">¶</a></dt>
<dd><p>The name of the GDAL driver used to handle the input file. For <code class="docutils literal notranslate"><span class="pre">GDALRaster</span></code>s created
from a file, the driver type is detected automatically. The creation of rasters from
scratch is an in-memory raster by default (<code class="docutils literal notranslate"><span class="pre">'MEM'</span></code>), but can be
altered as needed. For instance, use <code class="docutils literal notranslate"><span class="pre">GTiff</span></code> for a <code class="docutils literal notranslate"><span class="pre">GeoTiff</span></code> file.
For a list of file types, see also the <a class="reference external" href="https://gdal.org/drivers/raster/">GDAL Raster Formats</a> list.</p>
<p>An in-memory raster is created through the following example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span><span class="o">.</span><span class="n">driver</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;MEM&#39;</span>
</pre></div>
</div>
<p>A file based GeoTiff raster is created through the following example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">tempfile</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rstfile</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">NamedTemporaryFile</span><span class="p">(</span><span class="n">suffix</span><span class="o">=</span><span class="s1">&#39;.tif&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;driver&#39;</span><span class="p">:</span> <span class="s1">&#39;GTiff&#39;</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="n">rstfile</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">,</span>
<span class="gp">... </span>                  <span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">255</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">255</span><span class="p">,</span> <span class="s1">&#39;nr_of_bands&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;/tmp/tmp7x9H4J.tif&#39;           # The exact filename will be different on your computer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">driver</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;GTiff&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.width">
<code class="descname">width</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.width" title="永久链接至目标">¶</a></dt>
<dd><p>The width of the source in pixels (X-axis).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span><span class="o">.</span><span class="n">width</span>
<span class="go">10</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.height">
<code class="descname">height</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.height" title="永久链接至目标">¶</a></dt>
<dd><p>The height of the source in pixels (Y-axis).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span><span class="o">.</span><span class="n">height</span>
<span class="go">20</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.srs">
<code class="descname">srs</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.srs" title="永久链接至目标">¶</a></dt>
<dd><p>The spatial reference system of the raster, as a
<a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> instance. The SRS can be changed by
setting it to an other <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> or providing any input
that is accepted by the <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> constructor.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">srs</span><span class="o">.</span><span class="n">srid</span>
<span class="go">4326</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">srs</span> <span class="o">=</span> <span class="mi">3086</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">srs</span><span class="o">.</span><span class="n">srid</span>
<span class="go">3086</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.srid">
<code class="descname">srid</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.srid" title="永久链接至目标">¶</a></dt>
<dd><p>The Spatial Reference System Identifier (SRID) of the raster. This
property is a shortcut to getting or setting the SRID through the
<a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.srs" title="django.contrib.gis.gdal.GDALRaster.srs"><code class="xref py py-attr docutils literal notranslate"><span class="pre">srs</span></code></a> attribute.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">srid</span>
<span class="go">4326</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">srid</span> <span class="o">=</span> <span class="mi">3086</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">srid</span>
<span class="go">3086</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">srs</span><span class="o">.</span><span class="n">srid</span>  <span class="c1"># This is equivalent</span>
<span class="go">3086</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.geotransform">
<code class="descname">geotransform</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.geotransform" title="永久链接至目标">¶</a></dt>
<dd><p>The affine transformation matrix used to georeference the source, as a
tuple of six coefficients which map pixel/line coordinates into
georeferenced space using the following relationship:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Xgeo</span> <span class="o">=</span> <span class="n">GT</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="n">Xpixel</span><span class="o">*</span><span class="n">GT</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">Yline</span><span class="o">*</span><span class="n">GT</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">Ygeo</span> <span class="o">=</span> <span class="n">GT</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="n">Xpixel</span><span class="o">*</span><span class="n">GT</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="n">Yline</span><span class="o">*</span><span class="n">GT</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
<p>The same values can be retrieved by accessing the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.origin" title="django.contrib.gis.gdal.GDALRaster.origin"><code class="xref py py-attr docutils literal notranslate"><span class="pre">origin</span></code></a>
(indices 0 and 3), <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.scale" title="django.contrib.gis.gdal.GDALRaster.scale"><code class="xref py py-attr docutils literal notranslate"><span class="pre">scale</span></code></a> (indices 1 and 5) and <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.skew" title="django.contrib.gis.gdal.GDALRaster.skew"><code class="xref py py-attr docutils literal notranslate"><span class="pre">skew</span></code></a>
(indices 2 and 4) properties.</p>
<p>The default is <code class="docutils literal notranslate"><span class="pre">[0.0,</span> <span class="pre">1.0,</span> <span class="pre">0.0,</span> <span class="pre">0.0,</span> <span class="pre">0.0,</span> <span class="pre">-1.0]</span></code>.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">geotransform</span>
<span class="go">[0.0, 1.0, 0.0, 0.0, 0.0, -1.0]</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.origin">
<code class="descname">origin</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.origin" title="永久链接至目标">¶</a></dt>
<dd><p>Coordinates of the top left origin of the raster in the spatial
reference system of the source, as a point object with <code class="docutils literal notranslate"><span class="pre">x</span></code> and <code class="docutils literal notranslate"><span class="pre">y</span></code>
members.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">origin</span>
<span class="go">[0.0, 0.0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">origin</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">origin</span>
<span class="go">[1.0, 0.0]</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.scale">
<code class="descname">scale</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.scale" title="永久链接至目标">¶</a></dt>
<dd><p>Pixel width and height used for georeferencing the raster, as a point
object with <code class="docutils literal notranslate"><span class="pre">x</span></code> and <code class="docutils literal notranslate"><span class="pre">y</span></code>  members. See <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.geotransform" title="django.contrib.gis.gdal.GDALRaster.geotransform"><code class="xref py py-attr docutils literal notranslate"><span class="pre">geotransform</span></code></a> for more
information.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">scale</span>
<span class="go">[1.0, -1.0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">scale</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">scale</span>
<span class="go">[2.0, -1.0]</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.skew">
<code class="descname">skew</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.skew" title="永久链接至目标">¶</a></dt>
<dd><p>Skew coefficients used to georeference the raster, as a point object
with <code class="docutils literal notranslate"><span class="pre">x</span></code> and <code class="docutils literal notranslate"><span class="pre">y</span></code>  members. In case of north up images, these
coefficients are both <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">skew</span>
<span class="go">[0.0, 0.0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">skew</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="mi">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">skew</span>
<span class="go">[3.0, 0.0]</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.extent">
<code class="descname">extent</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.extent" title="永久链接至目标">¶</a></dt>
<dd><p>Extent (boundary values) of the raster source, as a 4-tuple
<code class="docutils literal notranslate"><span class="pre">(xmin,</span> <span class="pre">ymin,</span> <span class="pre">xmax,</span> <span class="pre">ymax)</span></code> in the spatial reference system of the
source.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">extent</span>
<span class="go">(0.0, -20.0, 10.0, 0.0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">origin</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="mi">100</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">extent</span>
<span class="go">(100.0, -20.0, 110.0, 0.0)</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.bands">
<code class="descname">bands</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.bands" title="永久链接至目标">¶</a></dt>
<dd><p>List of all bands of the source, as <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand" title="django.contrib.gis.gdal.GDALBand"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALBand</span></code></a> instances.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">,</span>
<span class="gp">... </span>                  <span class="s2">&quot;bands&quot;</span><span class="p">:</span> <span class="p">[{</span><span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]},</span> <span class="p">{</span><span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]}]})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">rst</span><span class="o">.</span><span class="n">bands</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">data</span><span class="p">()</span>
<span class="go">array([[ 2.,  3.]], dtype=float32)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.gis.gdal.GDALRaster.warp">
<code class="descname">warp</code>(<em>ds_input</em>, <em>resampling='NearestNeighbour'</em>, <em>max_error=0.0</em>)<a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.warp" title="永久链接至目标">¶</a></dt>
<dd><p>Returns a warped version of this raster.</p>
<p>The warping parameters can be specified through the <code class="docutils literal notranslate"><span class="pre">ds_input</span></code>
argument. The use of <code class="docutils literal notranslate"><span class="pre">ds_input</span></code> is analogous to the corresponding
argument of the class constructor. It is a dictionary with the
characteristics of the target raster. Allowed dictionary key values are
width, height, SRID, origin, scale, skew, datatype, driver, and name
(filename).</p>
<p>By default, the warp functions keeps most parameters equal to the
values of the original source raster, so only parameters that should be
changed need to be specified. Note that this includes the driver, so
for file-based rasters the warp function will create a new raster on
disk.</p>
<p>The only parameter that is set differently from the source raster is the
name. The default value of the raster name is the name of the source
raster appended with <code class="docutils literal notranslate"><span class="pre">'_copy'</span> <span class="pre">+</span> <span class="pre">source_driver_name</span></code>. For file-based
rasters it is recommended to provide the file path of the target raster.</p>
<p>The resampling algorithm used for warping can be specified with the
<code class="docutils literal notranslate"><span class="pre">resampling</span></code> argument. The default is <code class="docutils literal notranslate"><span class="pre">NearestNeighbor</span></code>, and the
other allowed values are <code class="docutils literal notranslate"><span class="pre">Bilinear</span></code>, <code class="docutils literal notranslate"><span class="pre">Cubic</span></code>, <code class="docutils literal notranslate"><span class="pre">CubicSpline</span></code>,
<code class="docutils literal notranslate"><span class="pre">Lanczos</span></code>, <code class="docutils literal notranslate"><span class="pre">Average</span></code>, and <code class="docutils literal notranslate"><span class="pre">Mode</span></code>.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">max_error</span></code> argument can be used to specify the maximum error
measured in input pixels that is allowed in approximating the
transformation. The default is 0.0 for exact calculations.</p>
<p>For users familiar with <code class="docutils literal notranslate"><span class="pre">GDAL</span></code>, this function has a similar
functionality to the <code class="docutils literal notranslate"><span class="pre">gdalwarp</span></code> command-line utility.</p>
<p>For example, the warp function can be used for aggregating a raster to
the double of its original pixel scale:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span>
<span class="gp">... </span>    <span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span> <span class="s2">&quot;srid&quot;</span><span class="p">:</span> <span class="mi">3086</span><span class="p">,</span>
<span class="gp">... </span>    <span class="s2">&quot;origin&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">500000</span><span class="p">,</span> <span class="mi">400000</span><span class="p">],</span>
<span class="gp">... </span>    <span class="s2">&quot;scale&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">100</span><span class="p">,</span> <span class="o">-</span><span class="mi">100</span><span class="p">],</span>
<span class="gp">... </span>    <span class="s2">&quot;bands&quot;</span><span class="p">:</span> <span class="p">[{</span><span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="nb">range</span><span class="p">(</span><span class="mi">36</span><span class="p">),</span> <span class="s2">&quot;nodata_value&quot;</span><span class="p">:</span> <span class="mi">99</span><span class="p">}]</span>
<span class="gp">... </span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">target</span> <span class="o">=</span> <span class="n">rst</span><span class="o">.</span><span class="n">warp</span><span class="p">({</span><span class="s2">&quot;scale&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">200</span><span class="p">,</span> <span class="o">-</span><span class="mi">200</span><span class="p">],</span> <span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">target</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span><span class="p">()</span>
<span class="go">array([[  7.,   9.,  11.],</span>
<span class="go">       [ 19.,  21.,  23.],</span>
<span class="go">       [ 31.,  33.,  35.]], dtype=float32)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.gis.gdal.GDALRaster.transform">
<code class="descname">transform</code>(<em>srs</em>, <em>driver=None</em>, <em>name=None</em>, <em>resampling='NearestNeighbour'</em>, <em>max_error=0.0</em>)<a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.transform" title="永久链接至目标">¶</a></dt>
<dd><p>Transforms this raster to a different spatial reference system
(<code class="docutils literal notranslate"><span class="pre">srs</span></code>), which may be a <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> object, or any
other input accepted by <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> (including spatial
reference WKT and PROJ strings, or an integer SRID).</p>
<p>It calculates the bounds and scale of the current raster in the new
spatial reference system and warps the raster using the
<a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.warp" title="django.contrib.gis.gdal.GDALRaster.warp"><code class="xref py py-attr docutils literal notranslate"><span class="pre">warp</span></code></a> function.</p>
<p>By default, the driver of the source raster is used and the name of the
raster is the original name appended with
<code class="docutils literal notranslate"><span class="pre">'_copy'</span> <span class="pre">+</span> <span class="pre">source_driver_name</span></code>. A different driver or name can be
specified with the <code class="docutils literal notranslate"><span class="pre">driver</span></code> and <code class="docutils literal notranslate"><span class="pre">name</span></code> arguments.</p>
<p>The default resampling algorithm is <code class="docutils literal notranslate"><span class="pre">NearestNeighbour</span></code> but can be
changed using the <code class="docutils literal notranslate"><span class="pre">resampling</span></code> argument. The default maximum allowed
error for resampling is 0.0 and can be changed using the <code class="docutils literal notranslate"><span class="pre">max_error</span></code>
argument. Consult the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.warp" title="django.contrib.gis.gdal.GDALRaster.warp"><code class="xref py py-attr docutils literal notranslate"><span class="pre">warp</span></code></a> documentation for detail
on those arguments.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span>
<span class="gp">... </span>    <span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span> <span class="s2">&quot;srid&quot;</span><span class="p">:</span> <span class="mi">3086</span><span class="p">,</span>
<span class="gp">... </span>    <span class="s2">&quot;origin&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">500000</span><span class="p">,</span> <span class="mi">400000</span><span class="p">],</span>
<span class="gp">... </span>    <span class="s2">&quot;scale&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">100</span><span class="p">,</span> <span class="o">-</span><span class="mi">100</span><span class="p">],</span>
<span class="gp">... </span>    <span class="s2">&quot;bands&quot;</span><span class="p">:</span> <span class="p">[{</span><span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="nb">range</span><span class="p">(</span><span class="mi">36</span><span class="p">),</span> <span class="s2">&quot;nodata_value&quot;</span><span class="p">:</span> <span class="mi">99</span><span class="p">}]</span>
<span class="gp">... </span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">target_srs</span> <span class="o">=</span> <span class="n">SpatialReference</span><span class="p">(</span><span class="mi">4326</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">target</span> <span class="o">=</span> <span class="n">rst</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="n">target_srs</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">target</span><span class="o">.</span><span class="n">origin</span>
<span class="go">[-82.98492744885776, 27.601924753080144]</span>
</pre></div>
</div>
<div class="versionchanged">
<span class="title">Changed in Django 3.2:</span> <p>Support for <a class="reference internal" href="#django.contrib.gis.gdal.SpatialReference" title="django.contrib.gis.gdal.SpatialReference"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpatialReference</span></code></a> <code class="docutils literal notranslate"><span class="pre">srs</span></code> was added</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.info">
<code class="descname">info</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.info" title="永久链接至目标">¶</a></dt>
<dd><p>Returns a string with a summary of the raster. This is equivalent to
the <a class="reference external" href="https://gdal.org/programs/gdalinfo.html">gdalinfo</a> command line utility.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.metadata">
<code class="descname">metadata</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.metadata" title="永久链接至目标">¶</a></dt>
<dd><p>The metadata of this raster, represented as a nested dictionary. The
first-level key is the metadata domain. The second-level contains the
metadata item names and values from each domain.</p>
<p>To set or update a metadata item, pass the corresponding metadata item
to the method using the nested structure described above. Only keys
that are in the specified dictionary are updated; the rest of the
metadata remains unchanged.</p>
<p>To remove a metadata item, use <code class="docutils literal notranslate"><span class="pre">None</span></code> as the metadata value.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">metadata</span>
<span class="go">{}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">metadata</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;DEFAULT&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;OWNER&#39;</span><span class="p">:</span> <span class="s1">&#39;Django&#39;</span><span class="p">,</span> <span class="s1">&#39;VERSION&#39;</span><span class="p">:</span> <span class="s1">&#39;1.0&#39;</span><span class="p">}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">metadata</span>
<span class="go">{&#39;DEFAULT&#39;: {&#39;OWNER&#39;: &#39;Django&#39;, &#39;VERSION&#39;: &#39;1.0&#39;}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">metadata</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;DEFAULT&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;OWNER&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;VERSION&#39;</span><span class="p">:</span> <span class="s1">&#39;2.0&#39;</span><span class="p">}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span><span class="o">.</span><span class="n">metadata</span>
<span class="go">{&#39;DEFAULT&#39;: {&#39;VERSION&#39;: &#39;2.0&#39;}}</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.vsi_buffer">
<code class="descname">vsi_buffer</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.vsi_buffer" title="永久链接至目标">¶</a></dt>
<dd><p>A <code class="docutils literal notranslate"><span class="pre">bytes</span></code> representation of this raster. Returns <code class="docutils literal notranslate"><span class="pre">None</span></code> for rasters
that are not stored in GDAL's virtual filesystem.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALRaster.is_vsi_based">
<code class="descname">is_vsi_based</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALRaster.is_vsi_based" title="永久链接至目标">¶</a></dt>
<dd><p>A boolean indicating if this raster is stored in GDAL's virtual
filesystem.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-gdalband">
<span id="gdalband"></span><h3><code class="docutils literal notranslate"><span class="pre">GDALBand</span></code><a class="headerlink" href="#gdalband" title="永久链接至标题">¶</a></h3>
<dl class="class">
<dt id="django.contrib.gis.gdal.GDALBand">
<em class="property">class </em><code class="descname">GDALBand</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand" title="永久链接至目标">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">GDALBand</span></code> instances are not created explicitly, but rather obtained
from a <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster" title="django.contrib.gis.gdal.GDALRaster"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALRaster</span></code></a> object, through its <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.bands" title="django.contrib.gis.gdal.GDALRaster.bands"><code class="xref py py-attr docutils literal notranslate"><span class="pre">bands</span></code></a>
attribute. The GDALBands contain the actual pixel values of the raster.</p>
<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALBand.description">
<code class="descname">description</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.description" title="永久链接至目标">¶</a></dt>
<dd><p>The name or description of the band, if any.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALBand.width">
<code class="descname">width</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.width" title="永久链接至目标">¶</a></dt>
<dd><p>The width of the band in pixels (X-axis).</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALBand.height">
<code class="descname">height</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.height" title="永久链接至目标">¶</a></dt>
<dd><p>The height of the band in pixels (Y-axis).</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALBand.pixel_count">
<code class="descname">pixel_count</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.pixel_count" title="永久链接至目标">¶</a></dt>
<dd><p>The total number of pixels in this band. Is equal to <code class="docutils literal notranslate"><span class="pre">width</span> <span class="pre">*</span> <span class="pre">height</span></code>.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.gis.gdal.GDALBand.statistics">
<code class="descname">statistics</code>(<em>refresh=False</em>, <em>approximate=False</em>)<a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.statistics" title="永久链接至目标">¶</a></dt>
<dd><p>Compute statistics on the pixel values of this band. The return value
is a tuple with the following structure:
<code class="docutils literal notranslate"><span class="pre">(minimum,</span> <span class="pre">maximum,</span> <span class="pre">mean,</span> <span class="pre">standard</span> <span class="pre">deviation)</span></code>.</p>
<p>If the <code class="docutils literal notranslate"><span class="pre">approximate</span></code> argument is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, the statistics may
be computed based on overviews or a subset of image tiles.</p>
<p>If the <code class="docutils literal notranslate"><span class="pre">refresh</span></code> argument is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, the statistics will be
computed from the data directly, and the cache will be updated with the
result.</p>
<p>If a persistent cache value is found, that value is returned. For
raster formats using Persistent Auxiliary Metadata (PAM) services, the
statistics might be cached in an auxiliary file. In some cases this
metadata might be out of sync with the pixel values or cause values
from a previous call to be returned which don't reflect the value of
the <code class="docutils literal notranslate"><span class="pre">approximate</span></code> argument. In such cases, use the <code class="docutils literal notranslate"><span class="pre">refresh</span></code>
argument to get updated values and store them in the cache.</p>
<p>For empty bands (where all pixel values are &quot;no data&quot;), all statistics
are returned as <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<p>The statistics can also be retrieved directly by accessing the
<a class="reference internal" href="#django.contrib.gis.gdal.GDALBand.min" title="django.contrib.gis.gdal.GDALBand.min"><code class="xref py py-attr docutils literal notranslate"><span class="pre">min</span></code></a>, <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand.max" title="django.contrib.gis.gdal.GDALBand.max"><code class="xref py py-attr docutils literal notranslate"><span class="pre">max</span></code></a>, <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand.mean" title="django.contrib.gis.gdal.GDALBand.mean"><code class="xref py py-attr docutils literal notranslate"><span class="pre">mean</span></code></a>, and <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand.std" title="django.contrib.gis.gdal.GDALBand.std"><code class="xref py py-attr docutils literal notranslate"><span class="pre">std</span></code></a> properties.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALBand.min">
<code class="descname">min</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.min" title="永久链接至目标">¶</a></dt>
<dd><p>The minimum pixel value of the band (excluding the &quot;no data&quot; value).</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALBand.max">
<code class="descname">max</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.max" title="永久链接至目标">¶</a></dt>
<dd><p>The maximum pixel value of the band (excluding the &quot;no data&quot; value).</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALBand.mean">
<code class="descname">mean</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.mean" title="永久链接至目标">¶</a></dt>
<dd><p>The mean of all pixel values of the band (excluding the &quot;no data&quot;
value).</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALBand.std">
<code class="descname">std</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.std" title="永久链接至目标">¶</a></dt>
<dd><p>The standard deviation of all pixel values of the band (excluding the
&quot;no data&quot; value).</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALBand.nodata_value">
<code class="descname">nodata_value</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.nodata_value" title="永久链接至目标">¶</a></dt>
<dd><p>The &quot;no data&quot; value for a band is generally a special marker value used
to mark pixels that are not valid data. Such pixels should generally not
be displayed, nor contribute to analysis operations.</p>
<p>To delete an existing &quot;no data&quot; value, set this property to <code class="docutils literal notranslate"><span class="pre">None</span></code>
(requires GDAL ≥ 2.1).</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.gis.gdal.GDALBand.datatype">
<code class="descname">datatype</code>(<em>as_string=False</em>)<a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.datatype" title="永久链接至目标">¶</a></dt>
<dd><p>The data type contained in the band, as an integer constant between 0
(Unknown) and 11. If <code class="docutils literal notranslate"><span class="pre">as_string</span></code> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the data type is
returned as a string with the following possible values:
<code class="docutils literal notranslate"><span class="pre">GDT_Unknown</span></code>, <code class="docutils literal notranslate"><span class="pre">GDT_Byte</span></code>, <code class="docutils literal notranslate"><span class="pre">GDT_UInt16</span></code>, <code class="docutils literal notranslate"><span class="pre">GDT_Int16</span></code>,
<code class="docutils literal notranslate"><span class="pre">GDT_UInt32</span></code>, <code class="docutils literal notranslate"><span class="pre">GDT_Int32</span></code>, <code class="docutils literal notranslate"><span class="pre">GDT_Float32</span></code>, <code class="docutils literal notranslate"><span class="pre">GDT_Float64</span></code>,
<code class="docutils literal notranslate"><span class="pre">GDT_CInt16</span></code>, <code class="docutils literal notranslate"><span class="pre">GDT_CInt32</span></code>, <code class="docutils literal notranslate"><span class="pre">GDT_CFloat32</span></code>, and <code class="docutils literal notranslate"><span class="pre">GDT_CFloat64</span></code>.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.gis.gdal.GDALBand.color_interp">
<code class="descname">color_interp</code>(<em>as_string=False</em>)<a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.color_interp" title="永久链接至目标">¶</a></dt>
<dd><p>The color interpretation for the band, as an integer between 0and 16.
If <code class="docutils literal notranslate"><span class="pre">as_string</span></code> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the data type is returned as a string
with the following possible values:
<code class="docutils literal notranslate"><span class="pre">GCI_Undefined</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_GrayIndex</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_PaletteIndex</span></code>,
<code class="docutils literal notranslate"><span class="pre">GCI_RedBand</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_GreenBand</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_BlueBand</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_AlphaBand</span></code>,
<code class="docutils literal notranslate"><span class="pre">GCI_HueBand</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_SaturationBand</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_LightnessBand</span></code>,
<code class="docutils literal notranslate"><span class="pre">GCI_CyanBand</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_MagentaBand</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_YellowBand</span></code>,
<code class="docutils literal notranslate"><span class="pre">GCI_BlackBand</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_YCbCr_YBand</span></code>, <code class="docutils literal notranslate"><span class="pre">GCI_YCbCr_CbBand</span></code>, and
<code class="docutils literal notranslate"><span class="pre">GCI_YCbCr_CrBand</span></code>. <code class="docutils literal notranslate"><span class="pre">GCI_YCbCr_CrBand</span></code> also represents <code class="docutils literal notranslate"><span class="pre">GCI_Max</span></code>
because both correspond to the integer 16, but only <code class="docutils literal notranslate"><span class="pre">GCI_YCbCr_CrBand</span></code>
is returned as a string.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.gis.gdal.GDALBand.data">
<code class="descname">data</code>(<em>data=None</em>, <em>offset=None</em>, <em>size=None</em>, <em>shape=None</em>)<a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.data" title="永久链接至目标">¶</a></dt>
<dd><p>The accessor to the pixel values of the <code class="docutils literal notranslate"><span class="pre">GDALBand</span></code>. Returns the complete
data array if no parameters are provided. A subset of the pixel array can
be requested by specifying an offset and block size as tuples.</p>
<p>If NumPy is available, the data is returned as NumPy array. For performance
reasons, it is highly recommended to use NumPy.</p>
<p>Data is written to the <code class="docutils literal notranslate"><span class="pre">GDALBand</span></code> if the <code class="docutils literal notranslate"><span class="pre">data</span></code> parameter is provided.
The input can be of one of the following types - packed string, buffer, list,
array, and NumPy array. The number of items in the input should normally
correspond to the total number of pixels in the band, or to the number
of pixels for a specific block of pixel values if the <code class="docutils literal notranslate"><span class="pre">offset</span></code> and
<code class="docutils literal notranslate"><span class="pre">size</span></code> parameters are provided.</p>
<p>If the number of items in the input is different from the target pixel
block, the <code class="docutils literal notranslate"><span class="pre">shape</span></code> parameter must be specified. The shape is a tuple
that specifies the width and height of the input data in pixels. The
data is then replicated to update the pixel values of the selected
block. This is useful to fill an entire band with a single value, for
instance.</p>
<p>例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span><span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">,</span> <span class="s1">&#39;datatype&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;nr_of_bands&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span> <span class="o">=</span> <span class="n">rst</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">16</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span><span class="o">.</span><span class="n">data</span><span class="p">()</span>
<span class="go">array([[ 0,  1,  2,  3],</span>
<span class="go">       [ 4,  5,  6,  7],</span>
<span class="go">       [ 8,  9, 10, 11],</span>
<span class="go">       [12, 13, 14, 15]], dtype=int8)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">offset</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">array([[ 5,  6],</span>
<span class="go">       [ 9, 10]], dtype=int8)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mi">4</span><span class="p">],</span> <span class="n">offset</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span><span class="o">.</span><span class="n">data</span><span class="p">()</span>
<span class="go">array([[ 0,  1,  2,  3],</span>
<span class="go">       [ 4, -1, -2,  7],</span>
<span class="go">       [ 8, -3, -4, 11],</span>
<span class="go">       [12, 13, 14, 15]], dtype=int8)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="s1">&#39;</span><span class="se">\x9d\xa8\xb3\xbe</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span><span class="o">.</span><span class="n">data</span><span class="p">()</span>
<span class="go">array([[  0,   1,   2,   3],</span>
<span class="go">       [  4, -99, -88,   7],</span>
<span class="go">       [  8, -77, -66,  11],</span>
<span class="go">       [ 12,  13,  14,  15]], dtype=int8)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span><span class="o">.</span><span class="n">data</span><span class="p">([</span><span class="mi">1</span><span class="p">],</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span><span class="o">.</span><span class="n">data</span><span class="p">()</span>
<span class="go">array([[1, 1, 1, 1],</span>
<span class="go">       [1, 1, 1, 1],</span>
<span class="go">       [1, 1, 1, 1],</span>
<span class="go">       [1, 1, 1, 1]], dtype=uint8)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bnd</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span>
<span class="go">array([[0, 0, 0, 0],</span>
<span class="go">       [1, 1, 1, 1],</span>
<span class="go">       [2, 2, 2, 2],</span>
<span class="go">       [3, 3, 3, 3]], dtype=uint8)</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.gis.gdal.GDALBand.metadata">
<code class="descname">metadata</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALBand.metadata" title="永久链接至目标">¶</a></dt>
<dd><p>The metadata of this band. The functionality is identical to
<a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.metadata" title="django.contrib.gis.gdal.GDALRaster.metadata"><code class="xref py py-attr docutils literal notranslate"><span class="pre">GDALRaster.metadata</span></code></a>.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-creating-rasters-from-data">
<span id="s-gdal-raster-ds-input"></span><span id="creating-rasters-from-data"></span><span id="gdal-raster-ds-input"></span><h3>Creating rasters from data<a class="headerlink" href="#creating-rasters-from-data" title="永久链接至标题">¶</a></h3>
<p>This section describes how to create rasters from scratch using the
<code class="docutils literal notranslate"><span class="pre">ds_input</span></code> parameter.</p>
<p>A new raster is created when a <code class="docutils literal notranslate"><span class="pre">dict</span></code> is passed to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster" title="django.contrib.gis.gdal.GDALRaster"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALRaster</span></code></a>
constructor. The dictionary contains defining parameters of the new raster,
such as the origin, size, or spatial reference system. The dictionary can also
contain pixel data and information about the format of the new raster. The
resulting raster can therefore be file-based or memory-based, depending on the
driver specified.</p>
<p>There's no standard for describing raster data in a dictionary or JSON flavor.
The definition of the dictionary input to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster" title="django.contrib.gis.gdal.GDALRaster"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALRaster</span></code></a> class is
therefore specific to Django. It's inspired by the <a class="reference external" href="https://geojson.org/">geojson</a> format, but the
<code class="docutils literal notranslate"><span class="pre">geojson</span></code> standard is currently limited to vector formats.</p>
<p>Examples of using the different keys when creating rasters can be found in the
documentation of the corresponding attributes and methods of the
<a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster" title="django.contrib.gis.gdal.GDALRaster"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALRaster</span></code></a> and <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand" title="django.contrib.gis.gdal.GDALBand"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALBand</span></code></a> classes.</p>
<div class="section" id="s-the-ds-input-dictionary">
<span id="the-ds-input-dictionary"></span><h4>The <code class="docutils literal notranslate"><span class="pre">ds_input</span></code> dictionary<a class="headerlink" href="#the-ds-input-dictionary" title="永久链接至标题">¶</a></h4>
<p>Only a few keys are required in the <code class="docutils literal notranslate"><span class="pre">ds_input</span></code> dictionary to create a raster:
<code class="docutils literal notranslate"><span class="pre">width</span></code>, <code class="docutils literal notranslate"><span class="pre">height</span></code>, and <code class="docutils literal notranslate"><span class="pre">srid</span></code>. All other parameters have default values
(see the table below). The list of keys that can be passed in the <code class="docutils literal notranslate"><span class="pre">ds_input</span></code>
dictionary is closely related but not identical to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster" title="django.contrib.gis.gdal.GDALRaster"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALRaster</span></code></a>
properties. Many of the parameters are mapped directly to those properties;
the others are described below.</p>
<p>The following table describes all keys that can be set in the <code class="docutils literal notranslate"><span class="pre">ds_input</span></code>
dictionary.</p>
<table class="docutils">
<colgroup>
<col width="23%" />
<col width="11%" />
<col width="67%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">键</th>
<th class="head">默认</th>
<th class="head">用法</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">srid</span></code></td>
<td>必须的</td>
<td>Mapped to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.srid" title="django.contrib.gis.gdal.GDALRaster.srid"><code class="xref py py-attr docutils literal notranslate"><span class="pre">srid</span></code></a> attribute</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">width</span></code></td>
<td>必须的</td>
<td>Mapped to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.width" title="django.contrib.gis.gdal.GDALRaster.width"><code class="xref py py-attr docutils literal notranslate"><span class="pre">width</span></code></a> attribute</td>
</tr>
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">height</span></code></td>
<td>必须的</td>
<td>Mapped to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.height" title="django.contrib.gis.gdal.GDALRaster.height"><code class="xref py py-attr docutils literal notranslate"><span class="pre">height</span></code></a> attribute</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">driver</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">MEM</span></code></td>
<td>Mapped to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.driver" title="django.contrib.gis.gdal.GDALRaster.driver"><code class="xref py py-attr docutils literal notranslate"><span class="pre">driver</span></code></a> attribute</td>
</tr>
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">name</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">''</span></code></td>
<td>See below</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">origin</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">0</span></code></td>
<td>Mapped to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.origin" title="django.contrib.gis.gdal.GDALRaster.origin"><code class="xref py py-attr docutils literal notranslate"><span class="pre">origin</span></code></a> attribute</td>
</tr>
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">scale</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">0</span></code></td>
<td>Mapped to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.scale" title="django.contrib.gis.gdal.GDALRaster.scale"><code class="xref py py-attr docutils literal notranslate"><span class="pre">scale</span></code></a> attribute</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">skew</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">0</span></code></td>
<td>Mapped to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.width" title="django.contrib.gis.gdal.GDALRaster.width"><code class="xref py py-attr docutils literal notranslate"><span class="pre">width</span></code></a> attribute</td>
</tr>
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">bands</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">[]</span></code></td>
<td>See below</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">nr_of_bands</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">0</span></code></td>
<td>See below</td>
</tr>
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">datatype</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">6</span></code></td>
<td>See below</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">papsz_options</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">{}</span></code></td>
<td>See below</td>
</tr>
</tbody>
</table>
<dl class="object">
<dt>
<code class="descname">name</code></dt>
<dd><p>String representing the name of the raster. When creating a file-based
raster, this parameter must be the file path for the new raster. If the
name starts with <code class="docutils literal notranslate"><span class="pre">/vsimem/</span></code>, the raster is created in GDAL's virtual
filesystem.</p>
</dd></dl>

<dl class="object">
<dt>
<code class="descname">datatype</code></dt>
<dd><p>Integer representing the data type for all the bands. Defaults to <code class="docutils literal notranslate"><span class="pre">6</span></code>
(Float32). All bands of a new raster are required to have the same datatype.
The value mapping is:</p>
<table class="docutils">
<colgroup>
<col width="10%" />
<col width="29%" />
<col width="61%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">值</th>
<th class="head">GDAL Pixel Type</th>
<th class="head">描述</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>1</td>
<td>GDT_Byte</td>
<td>Eight bit unsigned integer</td>
</tr>
<tr class="row-odd"><td>2</td>
<td>GDT_UInt16</td>
<td>Sixteen bit unsigned integer</td>
</tr>
<tr class="row-even"><td>3</td>
<td>GDT_Int16</td>
<td>Sixteen bit signed integer</td>
</tr>
<tr class="row-odd"><td>4</td>
<td>GDT_UInt32</td>
<td>Thirty-two bit unsigned integer</td>
</tr>
<tr class="row-even"><td>5</td>
<td>GDT_Int32</td>
<td>Thirty-two bit signed integer</td>
</tr>
<tr class="row-odd"><td>6</td>
<td>GDT_Float32</td>
<td>Thirty-two bit floating point</td>
</tr>
<tr class="row-even"><td>7</td>
<td>GDT_Float64</td>
<td>Sixty-four bit floating point</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="object">
<dt>
<code class="descname">nr_of_bands</code></dt>
<dd><p>Integer representing the number of bands of the raster. A raster can be
created without passing band data upon creation. If the number of bands
isn't specified, it's automatically calculated from the length of the
<code class="docutils literal notranslate"><span class="pre">bands</span></code> input. The number of bands can't be changed after creation.</p>
</dd></dl>

<dl class="object">
<dt>
<code class="descname">bands</code></dt>
<dd><p>A list of <code class="docutils literal notranslate"><span class="pre">band_input</span></code> dictionaries with band input data. The resulting
band indices are the same as in the list provided. The definition of the
band input dictionary is given below. If band data isn't provided, the
raster bands values are instantiated as an array of zeros and the &quot;no
data&quot; value is set to <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
</dd></dl>

<dl class="object">
<dt>
<code class="descname">papsz_options</code></dt>
<dd><p>A dictionary with raster creation options. The key-value pairs of the
input dictionary are passed to the driver on creation of the raster.</p>
<p>The available options are driver-specific and are described in the
documentation of each driver.</p>
<p>The values in the dictionary are not case-sensitive and are automatically
converted to the correct string format upon creation.</p>
<p>The following example uses some of the options available for the
<a class="reference external" href="https://gdal.org/drivers/raster/gtiff.html">GTiff driver</a>. The result is a compressed signed byte raster with an
internal tiling scheme. The internal tiles have a block size of 23 by 23:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">GDALRaster</span><span class="p">({</span>
<span class="gp">... </span>   <span class="s1">&#39;driver&#39;</span><span class="p">:</span> <span class="s1">&#39;GTiff&#39;</span><span class="p">,</span>
<span class="gp">... </span>   <span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;/path/to/new/file.tif&#39;</span><span class="p">,</span>
<span class="gp">... </span>   <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">4326</span><span class="p">,</span>
<span class="gp">... </span>   <span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">255</span><span class="p">,</span>
<span class="gp">... </span>   <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">255</span><span class="p">,</span>
<span class="gp">... </span>   <span class="s1">&#39;nr_of_bands&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="gp">... </span>   <span class="s1">&#39;papsz_options&#39;</span><span class="p">:</span> <span class="p">{</span>
<span class="gp">... </span>       <span class="s1">&#39;compress&#39;</span><span class="p">:</span> <span class="s1">&#39;packbits&#39;</span><span class="p">,</span>
<span class="gp">... </span>       <span class="s1">&#39;pixeltype&#39;</span><span class="p">:</span> <span class="s1">&#39;signedbyte&#39;</span><span class="p">,</span>
<span class="gp">... </span>       <span class="s1">&#39;tiled&#39;</span><span class="p">:</span> <span class="s1">&#39;yes&#39;</span><span class="p">,</span>
<span class="gp">... </span>       <span class="s1">&#39;blockxsize&#39;</span><span class="p">:</span> <span class="mi">23</span><span class="p">,</span>
<span class="gp">... </span>       <span class="s1">&#39;blockysize&#39;</span><span class="p">:</span> <span class="mi">23</span><span class="p">,</span>
<span class="gp">... </span>   <span class="p">}</span>
<span class="gp">... </span><span class="p">})</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="s-the-band-input-dictionary">
<span id="the-band-input-dictionary"></span><h4>The <code class="docutils literal notranslate"><span class="pre">band_input</span></code> dictionary<a class="headerlink" href="#the-band-input-dictionary" title="永久链接至标题">¶</a></h4>
<p>The <code class="docutils literal notranslate"><span class="pre">bands</span></code> key in the <code class="docutils literal notranslate"><span class="pre">ds_input</span></code> dictionary is a list of <code class="docutils literal notranslate"><span class="pre">band_input</span></code>
dictionaries. Each <code class="docutils literal notranslate"><span class="pre">band_input</span></code> dictionary can contain pixel values and the
&quot;no data&quot; value to be set on the bands of the new raster. The data array can
have the full size of the new raster or be smaller. For arrays that are smaller
than the full raster, the <code class="docutils literal notranslate"><span class="pre">size</span></code>, <code class="docutils literal notranslate"><span class="pre">shape</span></code>, and <code class="docutils literal notranslate"><span class="pre">offset</span></code> keys  control the
pixel values. The corresponding keys are passed to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand.data" title="django.contrib.gis.gdal.GDALBand.data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">data()</span></code></a>
method. Their functionality is the same as setting the band data with that
method. The following table describes the keys that can be used.</p>
<table class="docutils">
<colgroup>
<col width="16%" />
<col width="32%" />
<col width="52%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">键</th>
<th class="head">默认</th>
<th class="head">用法</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">nodata_value</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">None</span></code></td>
<td>Mapped to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand.nodata_value" title="django.contrib.gis.gdal.GDALBand.nodata_value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">nodata_value</span></code></a> attribute</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">data</span></code></td>
<td>Same as <code class="docutils literal notranslate"><span class="pre">nodata_value</span></code> or <code class="docutils literal notranslate"><span class="pre">0</span></code></td>
<td>Passed to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand.data" title="django.contrib.gis.gdal.GDALBand.data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">data()</span></code></a> method</td>
</tr>
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">size</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">(with,</span> <span class="pre">height)</span></code> of raster</td>
<td>Passed to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand.data" title="django.contrib.gis.gdal.GDALBand.data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">data()</span></code></a> method</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">shape</span></code></td>
<td>Same as size</td>
<td>Passed to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand.data" title="django.contrib.gis.gdal.GDALBand.data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">data()</span></code></a> method</td>
</tr>
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">offset</span></code></td>
<td><code class="docutils literal notranslate"><span class="pre">(0,</span> <span class="pre">0)</span></code></td>
<td>Passed to the <a class="reference internal" href="#django.contrib.gis.gdal.GDALBand.data" title="django.contrib.gis.gdal.GDALBand.data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">data()</span></code></a> method</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="s-using-gdal-s-virtual-filesystem">
<span id="s-gdal-raster-vsimem"></span><span id="using-gdal-s-virtual-filesystem"></span><span id="gdal-raster-vsimem"></span><h3>Using GDAL's Virtual Filesystem<a class="headerlink" href="#using-gdal-s-virtual-filesystem" title="永久链接至标题">¶</a></h3>
<p>GDAL has an internal memory-based filesystem, which allows treating blocks of
memory as files. It can be used to read and write <a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster" title="django.contrib.gis.gdal.GDALRaster"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALRaster</span></code></a> objects
to and from binary file buffers.</p>
<p>This is useful in web contexts where rasters might be obtained as a buffer
from a remote storage or returned from a view without being written to disk.</p>
<p><a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster" title="django.contrib.gis.gdal.GDALRaster"><code class="xref py py-class docutils literal notranslate"><span class="pre">GDALRaster</span></code></a> objects are created in the virtual filesystem when a
<code class="docutils literal notranslate"><span class="pre">bytes</span></code> object is provided as input, or when the file path starts with
<code class="docutils literal notranslate"><span class="pre">/vsimem/</span></code>.</p>
<p>Input provided as <code class="docutils literal notranslate"><span class="pre">bytes</span></code> has to be a full binary representation of a file.
For instance:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Read a raster as a file object from a remote source.</span>
<span class="o">&gt;&gt;&gt;</span> <span class="kn">from</span> <span class="nn">urllib.request</span> <span class="kn">import</span> <span class="n">urlopen</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">dat</span> <span class="o">=</span> <span class="n">urlopen</span><span class="p">(</span><span class="s1">&#39;http://example.com/raster.tif&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="c1"># Instantiate a raster from the bytes object.</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">(</span><span class="n">dat</span><span class="p">)</span>
<span class="c1"># The name starts with /vsimem/, indicating that the raster lives in the</span>
<span class="c1"># virtual filesystem.</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">rst</span><span class="o">.</span><span class="n">name</span>
<span class="s1">&#39;/vsimem/da300bdb-129d-49a8-b336-e410a9428dad&#39;</span>
</pre></div>
</div>
<p>To create a new virtual file-based raster from scratch, use the <code class="docutils literal notranslate"><span class="pre">ds_input</span></code>
dictionary representation and provide a <code class="docutils literal notranslate"><span class="pre">name</span></code> argument that starts with
<code class="docutils literal notranslate"><span class="pre">/vsimem/</span></code> (for detail of the dictionary representation, see
<a class="reference internal" href="#gdal-raster-ds-input"><span class="std std-ref">Creating rasters from data</span></a>). For virtual file-based rasters, the
<a class="reference internal" href="#django.contrib.gis.gdal.GDALRaster.vsi_buffer" title="django.contrib.gis.gdal.GDALRaster.vsi_buffer"><code class="xref py py-attr docutils literal notranslate"><span class="pre">vsi_buffer</span></code></a> attribute returns the <code class="docutils literal notranslate"><span class="pre">bytes</span></code> representation
of the raster.</p>
<p>Here's how to create a raster and return it as a file in an
<a class="reference internal" href="../../request-response.html#django.http.HttpResponse" title="django.http.HttpResponse"><code class="xref py py-class docutils literal notranslate"><span class="pre">HttpResponse</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">HttpResponse</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rst</span> <span class="o">=</span> <span class="n">GDALRaster</span><span class="p">({</span>
<span class="gp">... </span>    <span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;/vsimem/temporarymemfile&#39;</span><span class="p">,</span>
<span class="gp">... </span>    <span class="s1">&#39;driver&#39;</span><span class="p">:</span> <span class="s1">&#39;tif&#39;</span><span class="p">,</span>
<span class="gp">... </span>    <span class="s1">&#39;width&#39;</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span> <span class="s1">&#39;srid&#39;</span><span class="p">:</span> <span class="mi">3086</span><span class="p">,</span>
<span class="gp">... </span>    <span class="s1">&#39;origin&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">500000</span><span class="p">,</span> <span class="mi">400000</span><span class="p">],</span>
<span class="gp">... </span>    <span class="s1">&#39;scale&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">100</span><span class="p">,</span> <span class="o">-</span><span class="mi">100</span><span class="p">],</span>
<span class="gp">... </span>    <span class="s1">&#39;bands&#39;</span><span class="p">:</span> <span class="p">[{</span><span class="s1">&#39;data&#39;</span><span class="p">:</span> <span class="nb">range</span><span class="p">(</span><span class="mi">36</span><span class="p">),</span> <span class="s1">&#39;nodata_value&#39;</span><span class="p">:</span> <span class="mi">99</span><span class="p">}]</span>
<span class="gp">... </span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">HttpResponse</span><span class="p">(</span><span class="n">rast</span><span class="o">.</span><span class="n">vsi_buffer</span><span class="p">,</span> <span class="s1">&#39;image/tiff&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-settings">
<span id="settings"></span><h2>配置<a class="headerlink" href="#settings" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-gdal-library-path">
<span id="s-std:setting-GDAL_LIBRARY_PATH"></span><span id="gdal-library-path"></span><span id="std:setting-GDAL_LIBRARY_PATH"></span><h3><code class="docutils literal notranslate"><span class="pre">GDAL_LIBRARY_PATH</span></code><a class="headerlink" href="#gdal-library-path" title="永久链接至标题">¶</a></h3>
<p>A string specifying the location of the GDAL library.  Typically,
this setting is only used if the GDAL library is in a non-standard
location (e.g., <code class="docutils literal notranslate"><span class="pre">/home/john/lib/libgdal.so</span></code>).</p>
</div>
</div>
<div class="section" id="s-exceptions">
<span id="exceptions"></span><h2>异常<a class="headerlink" href="#exceptions" title="永久链接至标题">¶</a></h2>
<dl class="exception">
<dt id="django.contrib.gis.gdal.GDALException">
<em class="property">exception </em><code class="descname">GDALException</code><a class="headerlink" href="#django.contrib.gis.gdal.GDALException" title="永久链接至目标">¶</a></dt>
<dd><p>The base GDAL exception, indicating a GDAL-related error.</p>
</dd></dl>

<dl class="exception">
<dt id="django.contrib.gis.gdal.SRSException">
<em class="property">exception </em><code class="descname">SRSException</code><a class="headerlink" href="#django.contrib.gis.gdal.SRSException" title="永久链接至目标">¶</a></dt>
<dd><p>An exception raised when an error occurs when constructing or using a
spatial reference system object.</p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">GDAL API</a><ul>
<li><a class="reference internal" href="#overview">概况</a><ul>
<li><a class="reference internal" href="#sample-data">样本数据</a></li>
</ul>
</li>
<li><a class="reference internal" href="#vector-data-source-objects">矢量数据源对象</a><ul>
<li><a class="reference internal" href="#datasource"><code class="docutils literal notranslate"><span class="pre">DataSource</span></code></a></li>
<li><a class="reference internal" href="#layer"><code class="docutils literal notranslate"><span class="pre">Layer</span></code></a></li>
<li><a class="reference internal" href="#feature"><code class="docutils literal notranslate"><span class="pre">Feature</span></code></a></li>
<li><a class="reference internal" href="#field"><code class="docutils literal notranslate"><span class="pre">Field</span></code></a></li>
<li><a class="reference internal" href="#driver"><code class="docutils literal notranslate"><span class="pre">Driver</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#ogr-geometries">OGR Geometries</a><ul>
<li><a class="reference internal" href="#ogrgeometry"><code class="docutils literal notranslate"><span class="pre">OGRGeometry</span></code></a></li>
<li><a class="reference internal" href="#ogrgeomtype"><code class="docutils literal notranslate"><span class="pre">OGRGeomType</span></code></a></li>
<li><a class="reference internal" href="#envelope"><code class="docutils literal notranslate"><span class="pre">Envelope</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#coordinate-system-objects">Coordinate System Objects</a><ul>
<li><a class="reference internal" href="#spatialreference"><code class="docutils literal notranslate"><span class="pre">SpatialReference</span></code></a></li>
<li><a class="reference internal" href="#coordtransform"><code class="docutils literal notranslate"><span class="pre">CoordTransform</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#raster-data-objects">Raster Data Objects</a><ul>
<li><a class="reference internal" href="#gdalraster"><code class="docutils literal notranslate"><span class="pre">GDALRaster</span></code></a></li>
<li><a class="reference internal" href="#gdalband"><code class="docutils literal notranslate"><span class="pre">GDALBand</span></code></a></li>
<li><a class="reference internal" href="#creating-rasters-from-data">Creating rasters from data</a><ul>
<li><a class="reference internal" href="#the-ds-input-dictionary">The <code class="docutils literal notranslate"><span class="pre">ds_input</span></code> dictionary</a></li>
<li><a class="reference internal" href="#the-band-input-dictionary">The <code class="docutils literal notranslate"><span class="pre">band_input</span></code> dictionary</a></li>
</ul>
</li>
<li><a class="reference internal" href="#using-gdal-s-virtual-filesystem">Using GDAL's Virtual Filesystem</a></li>
</ul>
</li>
<li><a class="reference internal" href="#settings">配置</a><ul>
<li><a class="reference internal" href="#gdal-library-path"><code class="docutils literal notranslate"><span class="pre">GDAL_LIBRARY_PATH</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#exceptions">异常</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="geos.html"
                        title="上一章">GEOS API</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="geoip2.html"
                        title="下一章">用 GeoIP2 进行地理定位</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/ref/contrib/gis/gdal.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="geos.html" title="GEOS API">previous</a>
     |
    <a href="../../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="geoip2.html" title="用 GeoIP2 进行地理定位">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>